From 84a79be9c1ed4edbb8413ce6dcff6765e8fcdcee Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 20 Mar 2018 18:31:09 +0100 Subject: [PATCH] Only use plugins_config in redux --- client/coral-framework/components/Slot.js | 1 + client/coral-framework/services/bootstrap.js | 12 +++++- client/coral-framework/services/plugins.js | 39 +------------------- 3 files changed, 13 insertions(+), 39 deletions(-) diff --git a/client/coral-framework/components/Slot.js b/client/coral-framework/components/Slot.js index a2f90161f..048c4da80 100644 --- a/client/coral-framework/components/Slot.js +++ b/client/coral-framework/components/Slot.js @@ -30,6 +30,7 @@ class Slot extends React.Component { className, `talk-slot-${kebabCase(fill)}` )} + data-slot-name={fill} > {children} diff --git a/client/coral-framework/services/bootstrap.js b/client/coral-framework/services/bootstrap.js index 878c2e303..82a55cdec 100644 --- a/client/coral-framework/services/bootstrap.js +++ b/client/coral-framework/services/bootstrap.js @@ -66,8 +66,16 @@ function initExternalConfig({ store, pym, inIframe }) { } return new Promise(resolve => { pym.sendMessage('getConfig'); - pym.onMessage('config', config => { - store.dispatch(mergeConfig(JSON.parse(config))); + pym.onMessage('config', rawConfig => { + const config = JSON.parse(rawConfig); + if (config.plugin_config) { + console.warn( + 'Deprecation Warning: `config.plugin_config` will be phased out soon, please replace `config.plugin_config with `config.plugins_config`' + ); + config.plugins_config = config.plugin_config; + delete config.plugin_config; + } + store.dispatch(mergeConfig(config)); resolve(); }); }); diff --git a/client/coral-framework/services/plugins.js b/client/coral-framework/services/plugins.js index 3bc9bc5bc..bb16fc5e7 100644 --- a/client/coral-framework/services/plugins.js +++ b/client/coral-framework/services/plugins.js @@ -68,47 +68,14 @@ function addMetaDataToSlotComponents(plugins) { }); } -// @Deprecated -const showPluginConfigDeprecationWarningOnce = (() => { - let shown = false; - return () => { - if (!shown) { - shown = true; - console.warn( - `deprecation warning: config.plugin_config will be phased out soon, please replace calls from config.plugin_config to config.plugins_config` - ); - } - }; -})(); - /** * getSlotComponentProps calculate the props we would pass to the slot component. * query datas are only passed to the component if it is defined in `component.fragments`. */ function getSlotComponentProps(component, reduxState, props, queryData) { - // @Deprecated - const pluginsConfig = - get(reduxState, 'config.plugins_config') || - get(reduxState, 'config.plugin_config') || - emptyConfig; - - if ( - process.env.NODE_ENV !== 'production' && - !!get(reduxState, 'config.plugin_config') - ) { - showPluginConfigDeprecationWarningOnce(); - } - - console.log('slot plugins_config', get(reduxState, 'config.plugins_config')); - - const debugProps = pluginsConfig.debug - ? { - 'data-slot-name': props.fill, - } - : {}; + const pluginsConfig = get(reduxState, 'config.plugins_config') || emptyConfig; return { ...props, - ...debugProps, config: pluginsConfig, ...(component.fragments ? pick(queryData, Object.keys(component.fragments)) @@ -159,9 +126,7 @@ class PluginsService { */ getSlotElements(slot, reduxState, props = {}, options = {}) { const pluginsConfig = - get(reduxState, 'config.plugins_config') || - get(reduxState, 'config.plugin_config') || - emptyConfig; + get(reduxState, 'config.plugins_config') || emptyConfig; const { size = 0 } = options; const { queryData, rest } = splitProps(props);