Fix update of page attributes in hook "page"

This commit is contained in:
Samy Pesse
2016-10-13 21:52:54 +02:00
parent bb14f48c39
commit 2c3072fd8a
3 changed files with 17 additions and 10 deletions
+11 -9
View File
@@ -1,20 +1,22 @@
const { Record } = require('immutable');
const { Record, Map, fromJS } = require('immutable');
const DEFAULTS = {
title: '',
content: '',
dir: 'ltr',
depth: 1,
level: '',
previous: null,
next: null
title: '',
content: '',
dir: 'ltr',
depth: 1,
level: '',
previous: null,
next: null,
attributes: Map()
};
class Page extends Record(DEFAULTS) {
static create(state) {
return state instanceof Page ?
state : new Page({
...state
...state,
attributes: fromJS(state.attributes)
});
}
}
+1 -1
View File
@@ -19,7 +19,7 @@ function decodePage(output, page, result) {
}
// Update page attributes
const newAttributes = Immutable.fromJS(page.attributes);
const newAttributes = Immutable.fromJS(result.attributes);
page = page.set('attributes', newAttributes);
// GitBook 3
+5
View File
@@ -23,6 +23,11 @@ function encodePage(output, page) {
result.path = file.getPath();
result.rawPath = fs.resolve(result.path);
result.setAttribute = (key, value) => {
result.attributes[key] = value;
return result;
};
deprecate.field(output, 'page.progress', result, 'progress', function() {
return encodeProgress(output, page);
}, '"page.progress" property is deprecated');