diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-10-05 02:28:12 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-10-05 02:28:12 +0200 |
commit | 9ce3646d6e0d10035b6528e5384189fbed3d18c6 (patch) | |
tree | fc979cd4927178cf00fa3e3567b8c2c07176d338 /packages/gitbook-plugin-lunr/src/actions.js | |
parent | 45752fc79c9e3a5b7e84ed8572a8f0c12d8176b1 (diff) | |
download | gitbook-9ce3646d6e0d10035b6528e5384189fbed3d18c6.zip gitbook-9ce3646d6e0d10035b6528e5384189fbed3d18c6.tar.gz gitbook-9ce3646d6e0d10035b6528e5384189fbed3d18c6.tar.bz2 |
Add base for loading lunr index
Diffstat (limited to 'packages/gitbook-plugin-lunr/src/actions.js')
-rw-r--r-- | packages/gitbook-plugin-lunr/src/actions.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-lunr/src/actions.js b/packages/gitbook-plugin-lunr/src/actions.js new file mode 100644 index 0000000..8ead7ef --- /dev/null +++ b/packages/gitbook-plugin-lunr/src/actions.js @@ -0,0 +1,35 @@ +const GitBook = require('gitbook-core'); + +const TYPES = { + LOAD: 'lunr/load' +}; + +/** + * Load an index set + * @param {JSON} json + * @return {Action} + */ +function load(json) { + return { type: TYPES.LOAD, json }; +} + +/** + * Fetch an index + * @return {Action} + */ +function fetch() { + return (dispatch, getState) => { + return GitBook.Promise.resolve() + .then(() => { + // TODO: resolve the file correctly + return window.fetch('search_index.json'); + }) + .then(response => response.json()) + .then(json => dispatch(load(json))); + }; +} + +module.exports = { + TYPES, + fetch +}; |