Created
October 19, 2016 15:11
-
-
Save rijkvanzanten/e1f3c04635495f57aa27bfec6ee4be21 to your computer and use it in GitHub Desktop.
Redux Action Middleware which forwards actions to the server via socket.io when `server: true` is set in action object
This file contains hidden or 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
| const createSocketMiddleware = function(socket, {eventName = 'action'} = {}) { | |
| return ({dispatch}) => { | |
| socket.on(eventName, dispatch); | |
| return (next) => (action) => { | |
| if(action.hasOwnProperty('server')) socket.emit(eventName, action); | |
| return next(action); | |
| }; | |
| }; | |
| }; | |
| export default createSocketMiddleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment