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

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

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;

    }
};