diff options
Diffstat (limited to 'packages/gitbook-core/src/reducers/summary.js')
-rw-r--r-- | packages/gitbook-core/src/reducers/summary.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/packages/gitbook-core/src/reducers/summary.js b/packages/gitbook-core/src/reducers/summary.js new file mode 100644 index 0000000..0179ecc --- /dev/null +++ b/packages/gitbook-core/src/reducers/summary.js @@ -0,0 +1,56 @@ +const { Record, List } = require('immutable'); +const FileState = require('./file'); + +class SummaryArticle extends Record({ + title: '', + depth: 0, + path: '', + ref: '', + level: '', + articles: List() +}) { + constructor(state) { + super({ + ...state, + articles: (new List(state.articles)) + .map(article => new SummaryArticle(article)) + }); + } +} + +class SummaryPart extends Record({ + title: '', + articles: List() +}) { + constructor(state) { + super({ + ...state, + articles: (new List(state.articles)) + .map(article => new SummaryArticle(article)) + }); + } +} + + +class SummaryState extends Record({ + file: new FileState(), + parts: List() +}) { + constructor(state = {}) { + super({ + ...state, + file: new FileState(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); +}; |