From d4bf5fd4239a18dc45e74bb9a9418403ae9268a9 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Tue, 25 Jul 2017 21:20:04 +0700 Subject: [PATCH] Add subscription data events --- client/coral-embed-stream/src/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/coral-embed-stream/src/index.js b/client/coral-embed-stream/src/index.js index f66ca9205..7b9ac6895 100644 --- a/client/coral-embed-stream/src/index.js +++ b/client/coral-embed-stream/src/index.js @@ -16,7 +16,7 @@ import EventEmitterProvider from 'coral-framework/components/EventEmitterProvide const store = getStore(); const client = getClient(); -const eventEmitter = new EventEmitter(); +const eventEmitter = new EventEmitter({wildcard: true}); loadPluginsTranslations(); injectPluginsReducers(); @@ -54,11 +54,14 @@ if (!window.opener) { // Add a redux listener to pass through all actions to our event emitter. addListener((action) => { - // Ignore apollo actions. + // 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}); }); }