Closed ltjax closed 4 years ago
@ltjax Yes, indeed. I used the simple pattern of FirstOrDefault
to make it really simple. Still, I had no idea how to apply multiple reducers based on the same action.
I thought to use a Scan
operator but I do not know any in .NET. What was your idea?
Probably combine Where and Aggregate:
return _reducers
.Where(r => r.Types.Contains(actionName))
.Where(r => r.Reduce != null)
.Aggregate(state, (state, reducer) => reducer.Reduce(state, action))
That could work. We must also add some unit tests to verify that.
Done. You should see a 3.1 version very soon.
Right now, the mapping of reducers to actions seems to be 1:1 in ReduxSimple (Because of the FirstOrDefault in ReduxStore.Reduce). Or am I misinterpreting that? In the original redux, it is common to have multiple reducers react to the same action, especially when using slice reducers. See also: https://stackoverflow.com/questions/37111300/redux-why-not-put-actions-and-reducer-in-same-file
Maybe just replace the FirstOrDefault with a Where instead?