Last active
October 5, 2016 10:34
-
-
Save Scarysize/f8acd949b499c63a9bbbf79950679700 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
/** | |
* Creates a redux middleware which will send every action over a websocket connection. | |
* @param {WebSocket} socket The websocket connection object | |
* @return {Function} A redux middleware function | |
*/ | |
function createSyncMiddleware(socket) { | |
return () => next => action => { | |
// your actions should not contain any functions, which can´t be stringified | |
socket.send(JSON.stringify(action)); | |
// don´t forget this otherwise the middleware will swallow all actions | |
next(action); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment