summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/reducers/page.js
blob: 275fce75af05cced5d484d62b90c377c33f5e5a2 (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
const { Record } = require('immutable');
const ACTION_TYPES = require('../actions/TYPES');

const DEFAULTS = {
    title:   '',
    content: '',
    dir:     'ltr',
    depth:   1,
    level:   ''
};

class PageState extends Record(DEFAULTS) {
    static create(state) {
        return state instanceof PageState ?
            state : new PageState(state);
    }
}

module.exports = (state, action) => {
    state = PageState.create(state);

    switch (action.type) {

    case ACTION_TYPES.PAGE_FETCH_END:
        return state.merge(action.payload.page);

    default:
        return state;

    }
};