diff --git a/client/coral-admin/src/index.js b/client/coral-admin/src/index.js index e50d29408..42fa3705f 100644 --- a/client/coral-admin/src/index.js +++ b/client/coral-admin/src/index.js @@ -16,6 +16,8 @@ import {loadPluginsTranslations, injectPluginsReducers} from 'coral-framework/he const eventEmitter = new EventEmitter(); +// TODO: pass redux actions through the emitter. + loadPluginsTranslations(); injectPluginsReducers(); smoothscroll.polyfill(); diff --git a/client/coral-embed-stream/src/index.js b/client/coral-embed-stream/src/index.js index 7b9ac6895..c40df74f1 100644 --- a/client/coral-embed-stream/src/index.js +++ b/client/coral-embed-stream/src/index.js @@ -7,6 +7,7 @@ import './graphql'; import {addExternalConfig} from 'coral-embed-stream/src/actions/config'; import {getStore, injectReducers, addListener} from 'coral-framework/services/store'; import {getClient} from 'coral-framework/services/client'; +import {createReduxEmitter} from 'coral-framework/services/events'; import pym from 'coral-framework/services/pym'; import AppRouter from './AppRouter'; import {loadPluginsTranslations, injectPluginsReducers} from 'coral-framework/helpers/plugins'; @@ -52,18 +53,7 @@ if (!window.opener) { }); // Add a redux listener to pass through all actions to our event emitter. - addListener((action) => { - - // Handle apollo actions. - if (action.type.startsWith('APOLLO_')) { - if (action.type === 'APOLLO_SUBSCRIPTION_RESULT') { - const {operationName, variables, result: {data}} = action; - eventEmitter.emit(`subscription.${operationName}.data`, {variables, data}); - } - return; - } - eventEmitter.emit(`action.${action.type}`, {action}); - }); + addListener(createReduxEmitter(eventEmitter)); } render( diff --git a/client/coral-framework/services/events.js b/client/coral-framework/services/events.js new file mode 100644 index 000000000..a1a2f4448 --- /dev/null +++ b/client/coral-framework/services/events.js @@ -0,0 +1,14 @@ +export function createReduxEmitter(eventEmitter) { + return (action) => { + + // Handle apollo actions. + if (action.type.startsWith('APOLLO_')) { + if (action.type === 'APOLLO_SUBSCRIPTION_RESULT') { + const {operationName, variables, result: {data}} = action; + eventEmitter.emit(`subscription.${operationName}.data`, {variables, data}); + } + return; + } + eventEmitter.emit(`action.${action.type}`, {action}); + }; +}