summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/lib/createPlugin.js
blob: cb5d2be623d20c15fd3914bad4316c9fc0713725 (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
const Plugin = require('../models/Plugin');

/**
 * Create a plugin to extend the state and the views.
 *
 * @param  {Function(dispatch, state)} plugin.init
 * @param  {Function(state, action)} plugin.reduce
 * @param  {Object} plugin.actions
 * @return {Plugin}
 */
function createPlugin({ activate, deactivate, reduce, actions }) {
    const plugin = new Plugin({
        activate,
        deactivate,
        reduce,
        actions
    });

    if (typeof window !== 'undefined') {
        window.gitbookPlugins = window.gitbookPlugins || [];
        window.gitbookPlugins.push(plugin);
    }

    return plugin;
}

module.exports = createPlugin;