Reducer Chains and other Redux complexities

Reducers are called in order of their registration in the store (using composeReducer). So we need to make sure to not change the payload coz then the downstream reducer will not get the original payload.

Also, the reducer doesn’t have access to the store and so if it wants to get a store state owned by others, the component will have to pass it in the action payload…But this will not work coz the reducer can change that state and so the state in the payload is not state.

So, to solve this problem, the component will need to listen/observe the action as well, and when it is complete (ie when all reducers are done with the action) then it has to get the state and raise another action with just that state. This is the only way to make sure that the state is latest and not stale.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s