diff --git a/web/client/components/plugins/PluginsContainer.jsx b/web/client/components/plugins/PluginsContainer.jsx index 8f1f6440c5..43d0ac8b2b 100644 --- a/web/client/components/plugins/PluginsContainer.jsx +++ b/web/client/components/plugins/PluginsContainer.jsx @@ -11,8 +11,6 @@ const PluginsUtils = require('../../utils/PluginsUtils'); const assign = require('object-assign'); -const {get} = require('lodash'); - const PluginsContainer = React.createClass({ propTypes: { mode: React.PropTypes.string, @@ -23,8 +21,7 @@ const PluginsContainer = React.createClass({ className: React.PropTypes.string, style: React.PropTypes.object, pluginsState: React.PropTypes.object, - defaultMode: React.PropTypes.string, - stateSelector: React.PropTypes.func + defaultMode: React.PropTypes.string }, getDefaultProps() { return { @@ -36,8 +33,7 @@ const PluginsContainer = React.createClass({ id: "plugins-container", className: "plugins-container", style: {}, - pluginsState: {}, - stateSelector: () => ({}) + pluginsState: {} }; }, getInitialState() { @@ -51,11 +47,8 @@ const PluginsContainer = React.createClass({ componentWillReceiveProps(newProps) { this.loadPlugins(newProps.pluginsState); }, - getState(path) { - return this.props.stateSelector(path) || get(this.props.params, path); - }, getPluginDescriptor(plugin) { - return PluginsUtils.getPluginDescriptor(this.getState, this.props.plugins, + return PluginsUtils.getPluginDescriptor(this.props.plugins, this.props.pluginsConfig[this.props.mode], plugin, this.state.loadedPlugins); }, renderPlugins(plugins) { @@ -85,7 +78,7 @@ const PluginsContainer = React.createClass({ }, loadPlugins(state) { (this.props.pluginsConfig && this.props.pluginsConfig[this.props.mode] || []) - .map((plugin) => PluginsUtils.getPluginDescriptor(this.getState, this.props.plugins, + .map((plugin) => PluginsUtils.getPluginDescriptor(this.props.plugins, this.props.pluginsConfig[this.props.mode], plugin, this.state.loadedPlugins)) .filter((plugin) => plugin.impl.loadPlugin).forEach((plugin) => { if (!this.state.loadedPlugins[plugin.name]) { diff --git a/web/client/containers/Embedded.jsx b/web/client/containers/Embedded.jsx index afbab79633..8b9a852fdf 100644 --- a/web/client/containers/Embedded.jsx +++ b/web/client/containers/Embedded.jsx @@ -11,14 +11,11 @@ const {connect} = require('react-redux'); const url = require('url'); const urlQuery = url.parse(window.location.href, true).query; -const {get} = require('lodash'); + const PluginsContainer = connect((state) => ({ mode: (urlQuery.mode || (state.browser && state.browser.mobile ? 'mobile' : 'desktop')), - pluginsState: state && state.controls || {}, - stateSelector: (path) => { - return get(state, path); - } + pluginsState: state && state.controls || {} }))(require('../components/plugins/PluginsContainer')); const Embedded = React.createClass({ diff --git a/web/client/containers/MapViewer.jsx b/web/client/containers/MapViewer.jsx index c1ec270f77..583d1a55e3 100644 --- a/web/client/containers/MapViewer.jsx +++ b/web/client/containers/MapViewer.jsx @@ -14,15 +14,10 @@ const urlQuery = url.parse(window.location.href, true).query; const ConfigUtils = require('../utils/ConfigUtils'); -const {get} = require('lodash'); - const PluginsContainer = connect((state) => ({ pluginsConfig: state.plugins || ConfigUtils.getConfigProp('plugins') || null, mode: (urlQuery.mode || (state.browser && state.browser.mobile ? 'mobile' : 'desktop')), - pluginsState: state && state.controls || {}, - stateSelector: (path) => { - return get(state, path); - } + pluginsState: state && state.controls || {} }))(require('../components/plugins/PluginsContainer')); const MapViewer = React.createClass({ diff --git a/web/client/containers/Page.jsx b/web/client/containers/Page.jsx index b232f1282e..89df129751 100644 --- a/web/client/containers/Page.jsx +++ b/web/client/containers/Page.jsx @@ -11,13 +11,9 @@ const {connect} = require('react-redux'); const url = require('url'); const urlQuery = url.parse(window.location.href, true).query; -const {get} = require('lodash'); const PluginsContainer = connect((state) => ({ - mode: urlQuery.mode || ((urlQuery.mobile || (state.browser && state.browser.mobile)) ? 'mobile' : 'desktop'), - stateSelector: (path) => { - return get(state, path); - } + mode: urlQuery.mode || ((urlQuery.mobile || (state.browser && state.browser.mobile)) ? 'mobile' : 'desktop') }))(require('../components/plugins/PluginsContainer')); const Page = React.createClass({ diff --git a/web/client/examples/plugins/app.jsx b/web/client/examples/plugins/app.jsx index ff15721f02..4bf9a905b9 100644 --- a/web/client/examples/plugins/app.jsx +++ b/web/client/examples/plugins/app.jsx @@ -18,13 +18,9 @@ const startApp = () => { const {loadMapConfig} = require('../../actions/config'); const {loadLocale} = require('../../actions/locale'); const {loadPrintCapabilities} = require('../../actions/print'); - const {get} = require('lodash'); const PluginsContainer = connect((state) => ({ - pluginsState: state && state.controls || {}, - stateSelector: (path) => { - return get(state, path); - } + pluginsState: state && state.controls || {} }))(require('../../components/plugins/PluginsContainer')); const {plugins} = require('./plugins'); diff --git a/web/client/utils/PluginsUtils.js b/web/client/utils/PluginsUtils.js index f963d3d466..02982d812e 100644 --- a/web/client/utils/PluginsUtils.js +++ b/web/client/utils/PluginsUtils.js @@ -44,32 +44,7 @@ const getMorePrioritizedContainer = (pluginImpl, plugins, priority) => { }, {plugin: null, priority: priority}); }; -/*eslint-disable */ -const parseExpression = (state, requires, value) => { - const searchExpression = /^\{(.*?)\}$/; - const context = requires || {}; - const expression = searchExpression.exec(value); - if (expression !== null) { - return eval(expression[1]); - } - return value; -}; -/*eslint-enable */ - -const parsePluginConfig = (state, requires, cfg) => { - if (isArray(cfg)) { - return cfg.map((value) => parsePluginConfig(state, requires, value)); - } - if (isObject(cfg)) { - return Object.keys(cfg).reduce((previous, current) => { - const value = cfg[current]; - return assign(previous, {[current]: parsePluginConfig(state, requires, value)}); - }, {}); - } - return parseExpression(state, requires, cfg); -}; - -const getPluginItems = (state, plugins, pluginsConfig, name, id, isDefault, loadedPlugins) => { +const getPluginItems = (plugins, pluginsConfig, name, id, isDefault, loadedPlugins) => { return Object.keys(plugins) .filter((plugin) => plugins[plugin][name]) .filter((plugin) => { @@ -86,15 +61,40 @@ const getPluginItems = (state, plugins, pluginsConfig, name, id, isDefault, load item, pluginCfg.override && pluginCfg.override[name] || {}, { - cfg: pluginCfg && parsePluginConfig(state, plugins.requires, pluginCfg.cfg || {}) || undefined + cfg: pluginCfg && pluginCfg.cfg || undefined }, { plugin: pluginImpl, - items: getPluginItems(state, plugins, pluginsConfig, pluginName, null, true, loadedPlugins) + items: getPluginItems(plugins, pluginsConfig, pluginName, null, true, loadedPlugins) }); }); }; +/*eslint-disable */ +const parseExpression = (requires, value) => { + const searchExpression = /^\{(.*?)\}$/; + const context = requires || {}; + const expression = searchExpression.exec(value); + if (expression !== null) { + return eval(expression[1]); + } + return value; +}; +/*eslint-enable */ + + +const parsePluginConfig = (requires, cfg) => { + if (isArray(cfg)) { + return cfg.map((value) => parsePluginConfig(requires, value)); + } + if (isObject(cfg)) { + return Object.keys(cfg).reduce((previous, current) => { + const value = cfg[current]; + return assign(previous, {[current]: parsePluginConfig(requires, value)}); + }, {}); + } + return parseExpression(requires, cfg); +}; const getReducers = (plugins) => Object.keys(plugins).map((name) => plugins[name].reducers) .reduce((previous, current) => assign({}, previous, current), {}); @@ -106,7 +106,7 @@ const PluginsUtils = { getReducers, getPlugins: (plugins) => Object.keys(plugins).map((name) => plugins[name]) .reduce((previous, current) => assign({}, previous, omit(current, 'reducers')), {}), - getPluginDescriptor: (state, plugins, pluginsConfig, pluginDef, loadedPlugins = {}) => { + getPluginDescriptor: (plugins, pluginsConfig, pluginDef, loadedPlugins = {}) => { const name = isObject(pluginDef) ? pluginDef.name : pluginDef; const id = isObject(pluginDef) ? pluginDef.id : null; const stateSelector = isObject(pluginDef) ? pluginDef.stateSelector : id || undefined; @@ -120,8 +120,8 @@ const PluginsUtils = { id: id || name, name, impl: includeLoaded(name, loadedPlugins, (impl.loadPlugin || impl.displayName) ? impl : impl(stateSelector)), - cfg: isObject(pluginDef) ? parsePluginConfig(state, plugins.requires, pluginDef.cfg) : {}, - items: getPluginItems(state, plugins, pluginsConfig, name, id, isDefault, loadedPlugins) + cfg: isObject(pluginDef) ? parsePluginConfig(plugins.requires, pluginDef.cfg) : {}, + items: getPluginItems(plugins, pluginsConfig, name, id, isDefault, loadedPlugins) }; }, getMorePrioritizedContainer