Last active
January 24, 2018 13:26
-
-
Save arturparkhisenko/73139cfe0f6cba3892a2725e7a445dcf to your computer and use it in GitHub Desktop.
redux node
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
import makeStore from './src/store'; | |
import startServer from './src/server'; | |
export const store = makeStore(); | |
startServer(store); | |
store.dispatch({ | |
type:'SET_ENTRIES', | |
entries:require('./entries.json') | |
}); | |
store.dispatch({type:'NEXT'}); | |
store.dispatch({type:'VOTE', entry:'Trainspotting'}); | |
console.log(store.getState()); |
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
import Server from 'socket.io'; | |
export default function startServer(store) { | |
const io = new Server().attach(8090); | |
store.subscribe(() => { | |
io.emit('state', store.getState().toJS()) | |
} | |
); | |
io.on('connection', (socket) => { | |
socket.emit('state', store.getState().toJS()); | |
socket.on('action', store.dispatch.bind(store)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment