Only use plugins_config in redux

This commit is contained in:
Chi Vinh Le
2018-03-20 18:31:09 +01:00
parent dbe80c40d7
commit 84a79be9c1
3 changed files with 13 additions and 39 deletions
@@ -30,6 +30,7 @@ class Slot extends React.Component {
className,
`talk-slot-${kebabCase(fill)}`
)}
data-slot-name={fill}
>
{children}
</Component>
+10 -2
View File
@@ -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();
});
});
+2 -37
View File
@@ -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);