Skip to content

Instantly share code, notes, and snippets.

@Zapix
Last active December 21, 2017 12:14
Show Gist options
  • Select an option

  • Save Zapix/68a2f652feacaede20e64cc9db16ee75 to your computer and use it in GitHub Desktop.

Select an option

Save Zapix/68a2f652feacaede20e64cc9db16ee75 to your computer and use it in GitHub Desktop.
const cathcEventMiddleware = store => next => action => {
const eventType = 'eventType';
const eventListener = event => {
dispatch({
type: 'BROWSER_EVENT_FIRED',
eventType: eventType,
event
});
};
if (action.type === 'SUBSCRIBE') {
window.addEventListener(eventType, eventListener);
} else if (action.type === 'UNSUBSCRIBE') {
window.removeEventListener(eventType, eventListener)
}
return next(action):
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment