Skip to content

Instantly share code, notes, and snippets.

@Scarysize
Last active May 6, 2020 05:50
Show Gist options
  • Save Scarysize/a5548907e0f1db201316f957b8d65521 to your computer and use it in GitHub Desktop.
Save Scarysize/a5548907e0f1db201316f957b8d65521 to your computer and use it in GitHub Desktop.
export default function createSocketListener(socket, store) {
return event => {
const action = JSON.parse(event.data);
store.dispatch(action);
}
}
// when creating your websocket connection
const socket = new WebSocket(/*...*/);
if (/* check if this is a 'follower' */) {
socket.addEventListener('message', createSocketListener(socket, store));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment