Skip to content

Instantly share code, notes, and snippets.

@arturparkhisenko
Last active January 24, 2018 13:26
Show Gist options
  • Save arturparkhisenko/73139cfe0f6cba3892a2725e7a445dcf to your computer and use it in GitHub Desktop.
Save arturparkhisenko/73139cfe0f6cba3892a2725e7a445dcf to your computer and use it in GitHub Desktop.
redux node
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());
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