diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-09-22 10:37:06 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-09-22 10:37:06 +0200 |
commit | f49089a7d3a6fd5523c71e06e5e0d132bb6ffd9a (patch) | |
tree | 4656866589cd5e46650b867cc2447619ea11bb3a /packages/gitbook-core/src/reducers/summary.js | |
parent | 0b1888e184d3f995c3130daf794416ad0a4312bc (diff) | |
download | gitbook-f49089a7d3a6fd5523c71e06e5e0d132bb6ffd9a.zip gitbook-f49089a7d3a6fd5523c71e06e5e0d132bb6ffd9a.tar.gz gitbook-f49089a7d3a6fd5523c71e06e5e0d132bb6ffd9a.tar.bz2 |
Add immutable state for readme/summary
Add shapes for these states
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); +}; |