summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-lunr/src/reducer.js
blob: 48c3c23ddd0d968fe2a55aa67bd8ef93070079c2 (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 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;
    }
});