summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-lunr/src/actions.js
blob: 8ead7efa4f03c46e1a3cee1cfc696ead72ce8b61 (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
32
33
34
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
};