summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/reducers/summary.js
blob: 60568eff0fec16e7af08439df03f992ae0d1e83c (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
const { Record, List } = require('immutable');

const File = require('../models/File');
const SummaryPart = require('../models/SummaryPart');


class SummaryState extends Record({
    file: new File(),
    parts: List()
}) {
    constructor(state = {}) {
        super({
            ...state,
            file:  new File(state.file),
            parts: (new List(state.parts))
                .map(article => new SummaryPart(article))
        });
    }

    static create(state) {
        return state instanceof SummaryState ?
            state : new SummaryState(state);
    }
}

module.exports = (state, action) => {
    return SummaryState.create(state);
};