function sendMessage(id, payload) {
return {
type: SEND_MESSAGE,
id,
payload
}
}
const websocketMiddleware = store => next => action => {
switch (action.type) {
case SEND_MESSAGE:
socket.emit(...)
return next(action);
case RECEIVE_MESSAGE:
// read the message.. somehow...
return next(action);
}
}
const store = applyMiddleware(websocketMiddleware)(createStore(reducer))