redux with sockjs
Test
npm test
Usage
for es6 project, babel-preset-stage-0 syntax
on server
const channel = channel
on browser use webpack or browserify
/* when use actionCreator, the reduxSockjs must be used and vice versa */ const channel = /* channel must bound to createAction first, then use redux middle to create store */ const createAction = const createUser = const userReducer = // use reduxPromise before reduxSockjs const store = channel // it is async, when data send to server and broadcast to browser // store.getState().user will be [{ name: 'bob' }]
if some server operation take too long, you can use promise action
/* when use actionCreator, the reduxSockjs must be used and vice versa */ const channel = /* channel must bound to createAction first, then use redux middle to create store */ const createAction = const createUser = const userReducer = /* use reduxPromise before reduxSockjs */ const store = channel // it is async, when data send to server and broadcast to browser // store.getState().user will be [{ name: 'bob' }]
Server API
startReduxServer
if no param, just startServer(), it will use default param as below
reduxChannel instance method
reduxChannel on server inherites nodejs "events", and has some own method as below
- receive(func)
can receive many functions, when receive data, each will be called with data
- remove(func)
remove func from receive data functions
- send(data)
send data to client async
-
broadcast(data)
like send, but send data to all connected client
Client API
startReduxClient
if no param, just startClient(), it will use default param as below the protocal should correspond to the server protocal
const reduxChannel =
reduxChannel instance method
reduxChannel on client inherites nodejs "events", and has some own method as below
-
reconnect(interval, maxRetry)
when reconnect, it`s emitter property will be replaced new one
-
receive(func)
can receive many functions, when receive data, each will be called with data
- remove(func)
remove func from receive data functions
- send(data)
send data to server async
actionCreator
receive an return value of startReduxClient return a function to create action
const createAction = const actionAddTodo =