summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/lib/createPlugin.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-09-29 16:03:16 +0200
committerSamy Pesse <samypesse@gmail.com>2016-09-29 16:03:16 +0200
commit7f283791544195fa70c51003db9be3f029c014ef (patch)
tree4a5ac11ed2a3f1b6e6e0a8d3e7bedd641c0f186f /packages/gitbook-core/src/lib/createPlugin.js
parent6f98ee18468e88af01a066eb6e203e4d6ef0a52c (diff)
downloadgitbook-7f283791544195fa70c51003db9be3f029c014ef.zip
gitbook-7f283791544195fa70c51003db9be3f029c014ef.tar.gz
gitbook-7f283791544195fa70c51003db9be3f029c014ef.tar.bz2
Fix dist command
Diffstat (limited to 'packages/gitbook-core/src/lib/createPlugin.js')
-rw-r--r--packages/gitbook-core/src/lib/createPlugin.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/gitbook-core/src/lib/createPlugin.js b/packages/gitbook-core/src/lib/createPlugin.js
new file mode 100644
index 0000000..7a49053
--- /dev/null
+++ b/packages/gitbook-core/src/lib/createPlugin.js
@@ -0,0 +1,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;