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

const NavigationState = Record({
    loading: false,
    error:   null
});

function reduceNavigation(state, action) {
    state = state || NavigationState();
    switch (action.type) {

    case ACTION_TYPES.PAGE_FETCH_START:
        return state.merge({
            loading: true
        });

    case ACTION_TYPES.PAGE_FETCH_END:
        return state.merge({
            loading: false
        });

    case ACTION_TYPES.PAGE_FETCH_ERROR:
        return state.merge({
            loading: false,
            error:   action.error
        });

    default:
        return state;

    }
}

module.exports = reduceNavigation;