mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 11:26:31 +00:00
Start basis of gitbook-core
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "gitbook-core",
|
||||
"version": "0.0.0",
|
||||
"description": "Core for GitBook plugins API",
|
||||
"main": "./src/index.js",
|
||||
"dependencies": {
|
||||
"immutable": "^3.8.1",
|
||||
"react": "^15.3.1",
|
||||
"react-dom": "^15.3.1",
|
||||
"react-redux": "^4.4.5",
|
||||
"redux": "^3.5.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/GitbookIO/gitbook.git"
|
||||
},
|
||||
"author": "GitBook Inc. <contact@gitbook.com>",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/GitbookIO/gitbook/issues"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
const React = require('react');
|
||||
|
||||
const InjectedComponent = React.createClass({
|
||||
render() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = InjectedComponent;
|
||||
@@ -0,0 +1,9 @@
|
||||
const React = require('react');
|
||||
|
||||
const InjectedComponentSet = React.createClass({
|
||||
render() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = InjectedComponentSet;
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
module.exports = {
|
||||
REGISTER_COMPONENT: 'components:register',
|
||||
UNREGISTER_COMPONENT: 'components:unregister'
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
const ReactRedux = require('react-redux');
|
||||
|
||||
/**
|
||||
* Connect a component to the GitBook store
|
||||
* @param {ReactComponent} Component
|
||||
* @param {Function} mapStateToProps
|
||||
* @return {ReactComponent}
|
||||
*/
|
||||
function connect(Component, mapStateToProps) {
|
||||
return ReactRedux.connect(Component, mapStateToProps);
|
||||
}
|
||||
|
||||
module.exports = connect;
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
/**
|
||||
* Create a plugin to extend the state and the views.
|
||||
*
|
||||
* @param {Function(dispatch, state)} onInitialState
|
||||
* @param {Funciton(state, action)} onReduceState
|
||||
* @return {Plugin}
|
||||
*/
|
||||
function createPlugin(onInitialState, onReduceState) {
|
||||
return {
|
||||
onInitialState,
|
||||
onReduceState
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = createPlugin;
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
/**
|
||||
* Helper to create a reducer that extend the store.
|
||||
*
|
||||
* @param {String} property
|
||||
* @param {Function(state, action): state} reduce
|
||||
* @return {Function(state, action): state}
|
||||
*/
|
||||
function createReducer(name, reduce) {
|
||||
return function(state, action) {
|
||||
const value = state[name];
|
||||
state[name] = reduce(value, action);
|
||||
return state;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = createReducer;
|
||||
@@ -0,0 +1,32 @@
|
||||
const Redux = require('redux');
|
||||
const ReduxThunk = require('redux-thunk').default;
|
||||
|
||||
const reducers = require('./reducers');
|
||||
|
||||
/**
|
||||
* Create a new redux store from an initial state and a list of plugins.
|
||||
* Each plugin entry is the result of {createPlugin}.
|
||||
*
|
||||
* @param {Array<Plugin>} plugins
|
||||
* @param {Object} initialState
|
||||
* @return {ReduxStore} store
|
||||
*/
|
||||
function createStore(plugins, initialState) {
|
||||
const pluginReducers = plugins.map(plugin => plugin.onReduceState);
|
||||
const reducer = Redux.combine(reducers, ...pluginReducers);
|
||||
|
||||
const store = Redux.createStore(
|
||||
reducer,
|
||||
initialState,
|
||||
Redux.applyMiddleware(ReduxThunk)
|
||||
);
|
||||
|
||||
// Initialize the plugins
|
||||
plugins.forEach(plugin => {
|
||||
plugin.onInitialState(store.dispatch, store.getState);
|
||||
});
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
module.exports = createStore;
|
||||
@@ -0,0 +1,17 @@
|
||||
const ACTIONS = require('./actions/TYPES');
|
||||
const connect = require('./connect');
|
||||
const InjectedComponent = require('./InjectedComponent');
|
||||
const InjectedComponentSet = require('./InjectedComponentSet');
|
||||
const createPlugin = require('./createPlugin');
|
||||
const createReducer = require('./createReducer');
|
||||
const createStore = require('./createStore');
|
||||
|
||||
module.exports = {
|
||||
ACTIONS,
|
||||
connect,
|
||||
createPlugin,
|
||||
createReducer,
|
||||
createStore,
|
||||
InjectedComponent,
|
||||
InjectedComponentSet
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
const Immutable = require('immutable');
|
||||
|
||||
function reduceComponents(state, action) {
|
||||
|
||||
}
|
||||
|
||||
module.exports = reduceComponents;
|
||||
@@ -0,0 +1,5 @@
|
||||
const Redux = require('redux');
|
||||
|
||||
module.exports = Redux.combineReducers({
|
||||
components: require('./components')
|
||||
});
|
||||
Reference in New Issue
Block a user