Refactor listener

This commit is contained in:
Chi Vinh Le
2017-07-25 23:26:23 +07:00
parent 8ecf55610c
commit 1473c778a5
3 changed files with 18 additions and 12 deletions
+14
View File
@@ -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});
};
}