summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/models/StateSummary.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-core/src/models/StateSummary.js')
-rw-r--r--packages/gitbook-core/src/models/StateSummary.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/gitbook-core/src/models/StateSummary.js b/packages/gitbook-core/src/models/StateSummary.js
new file mode 100644
index 0000000..f268f34
--- /dev/null
+++ b/packages/gitbook-core/src/models/StateSummary.js
@@ -0,0 +1,31 @@
+const { Record, List } = require('immutable');
+
+const File = require('../models/File');
+const SummaryPart = require('../models/SummaryPart');
+
+const DEFAULTS = {
+ file: new File(),
+ parts: List()
+};
+
+/**
+ * State for the summary.
+ * @type {Record}
+ */
+class StateSummary extends Record(DEFAULTS) {
+ 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 StateSummary ?
+ state : new StateSummary(state);
+ }
+}
+
+module.exports = StateSummary;