blob: 7a49053ffa95728ad3e7629ac9f5d5eeb7febcc4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
const defaultInit = ((dispatch, getState) => {});
const defaultReduce = ((state, action) => state);
/**
* Create a plugin to extend the state and the views.
*
* @param {Function(dispatch, state)} onInitialState
* @param {Funciton(state, action)} onReduceState
* @return {Plugin}
*/
function createPlugin({ init, reduce, actions }) {
init = init || defaultInit;
reduce = reduce || defaultReduce;
actions = actions || {};
const plugin = {
init,
reduce,
actions
};
if (typeof window !== 'undefined') {
window.gitbookPlugins = window.gitbookPlugins || [];
window.gitbookPlugins.push(plugin);
}
return plugin;
}
module.exports = createPlugin;
|