Skip to content

Instantly share code, notes, and snippets.

@whittle
Created August 12, 2015 16:25
Show Gist options
  • Save whittle/55a4d4d89fc76f37c797 to your computer and use it in GitHub Desktop.
Save whittle/55a4d4d89fc76f37c797 to your computer and use it in GitHub Desktop.
'use strict';
var debug = require('debug')('papillon:config_plugin');
var iMap = require('immutable').Map;
function configPlugin() {
return {
name: 'ConfigPlugin',
plugContext: function(options, context, app) {
var _state;
if (options.config) {
_state = iMap(options.config);
}
var plugin = {
dehydrate: function() {
return _state;
},
rehydrate: function(state) {
_state = iMap(state);
},
getConfig: function(key) {
if (!_state.has(key)) {
debug('Missing config', key);
}
return _state.get(key);
},
plugActionContext: function(actionContext, context, app) {
actionContext.getConfig = plugin.getConfig;
},
plugComponentContext: function(componentContext, context, app) {
componentContext.getConfig = plugin.getConfig;
},
plugStoreContext: function(storeContext, context, app) {
storeContext.getConfig = plugin.getConfig;
}
};
return plugin;
}
};
}
module.exports = configPlugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment