diff options
author | Samy Pessé <samypesse@gmail.com> | 2017-02-17 21:08:00 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2017-02-17 21:08:00 +0100 |
commit | dd43b0a6091ef3c830d92305cb57ab3c19eaf998 (patch) | |
tree | 976bee1d1bef641aec9a715da6e512afe6350561 | |
parent | 0198dd291a93e6a577af082b798385d5498b6ec3 (diff) | |
download | gitbook-dd43b0a6091ef3c830d92305cb57ab3c19eaf998.zip gitbook-dd43b0a6091ef3c830d92305cb57ab3c19eaf998.tar.gz gitbook-dd43b0a6091ef3c830d92305cb57ab3c19eaf998.tar.bz2 |
Add model for config instead of using fromJS
-rw-r--r-- | packages/gitbook-core/src/models/Config.js | 32 | ||||
-rw-r--r-- | packages/gitbook-core/src/reducers/config.js | 7 |
2 files changed, 36 insertions, 3 deletions
diff --git a/packages/gitbook-core/src/models/Config.js b/packages/gitbook-core/src/models/Config.js new file mode 100644 index 0000000..50abef2 --- /dev/null +++ b/packages/gitbook-core/src/models/Config.js @@ -0,0 +1,32 @@ +const { Map, fromJS } = require('immutable'); + +/** + * Configuration from the book. + * @type {Class} + */ +class Config extends Map { + + /** + * Create a config instance from values. + * @param {Mixed} values + * @return {Config} + */ + static create(values) { + return values instanceof Config ? + values : new Config(fromJS(values)); + } + + /** + * Get configuration for a plugin. + * @param {String} pluginName + * @return {Map} + */ + getForPlugin(pluginName) { + return this.getIn([ + 'pluginsConfig', pluginName + ]); + } + +} + +module.exports = Config; diff --git a/packages/gitbook-core/src/reducers/config.js b/packages/gitbook-core/src/reducers/config.js index a49c602..2ef1ce3 100644 --- a/packages/gitbook-core/src/reducers/config.js +++ b/packages/gitbook-core/src/reducers/config.js @@ -1,12 +1,13 @@ -const { fromJS } = require('immutable'); const ACTION_TYPES = require('../actions/TYPES'); +const Config = require('../models/Config'); module.exports = (state, action) => { - state = fromJS(state); + state = Config.create(state); + switch (action.type) { case ACTION_TYPES.PAGE_FETCH_END: - return fromJS(action.payload.config); + return Config.create(action.payload.config); default: return state; |