Closed
Description
I'm working on a chat app built with React.js and Flux. As I read the docs of Redux the combineReducer
function appears strange to me. For example:
There are three stores called messageStore
, unreadStore
, threadStore
. And there's and action called NEW_MESSAGE
. All three stores will update on new messages. In Redux, the stores are reducers combined with combineReducer
like:
message = (state=[], action) ->
switch action.type
when NEW_MESSAGE
state # new state
unread = (state=[], action) ->
switch action.type
when NEW_MESSAGE
state # new state
thread = (state=[], action) ->
switch action.type
when NEW_MESSAGE
state # new state
combineReducer {message, unread, thread}
It appears to me the in such cases, splitting reducers is not making my life easier. However a giant store built with immutable-js maybe a better solution for this. Like:
initialState = Immutable.fromJS
message: []
unread: []
thread: []
allStore = (store=initialState, action) ->
switch action.type
when NEW_MESSAGE
initialState
.updateIn ['message'], (messages) -> messages # updated
.updateIn ['urnead'], (urneads) -> unreads # updated
.updateIn ['thread'], (threads) -> threads # updated