summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-lunr/src/reducer.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-10-05 02:28:12 +0200
committerSamy Pesse <samypesse@gmail.com>2016-10-05 02:28:12 +0200
commit9ce3646d6e0d10035b6528e5384189fbed3d18c6 (patch)
treefc979cd4927178cf00fa3e3567b8c2c07176d338 /packages/gitbook-plugin-lunr/src/reducer.js
parent45752fc79c9e3a5b7e84ed8572a8f0c12d8176b1 (diff)
downloadgitbook-9ce3646d6e0d10035b6528e5384189fbed3d18c6.zip
gitbook-9ce3646d6e0d10035b6528e5384189fbed3d18c6.tar.gz
gitbook-9ce3646d6e0d10035b6528e5384189fbed3d18c6.tar.bz2
Add base for loading lunr index
Diffstat (limited to 'packages/gitbook-plugin-lunr/src/reducer.js')
-rw-r--r--packages/gitbook-plugin-lunr/src/reducer.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-lunr/src/reducer.js b/packages/gitbook-plugin-lunr/src/reducer.js
new file mode 100644
index 0000000..48c3c23
--- /dev/null
+++ b/packages/gitbook-plugin-lunr/src/reducer.js
@@ -0,0 +1,27 @@
+const lunr = require('lunr');
+const GitBook = require('gitbook-core');
+const { Record } = GitBook.Immutable;
+
+const { TYPES } = require('./actions');
+
+const LunrState = Record({
+ idx: null,
+ store: {}
+});
+
+module.exports = GitBook.createReducer('lunr', (state, action) => {
+ state = state || LunrState();
+
+ switch (action.type) {
+
+ case TYPES.LOAD:
+ return state
+ .set('idx', lunr.Index.load(action.json.index))
+ .merge({
+ store: action.json.store
+ });
+
+ default:
+ return state;
+ }
+});