Last active
May 6, 2020 05:50
-
-
Save Scarysize/a5548907e0f1db201316f957b8d65521 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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