Closed e-r-w closed 7 years ago
Also, thanks! We can only hope its making life easier :)
Yeah so the reducer would be a pure function then. In the event that the action matches the reducer, it will behave the same as before. However if the action is not matched it will return the state passed in or the initial state the user has specified in the event that the state passed in is undefined
We would need to formulate a way to get the last known state from the reducer then, else we deprecate that functionality for many users.
The reducer's job is to determine the next state given a previous state and an action. You can get the current state with getState() but you shouldn't be relying on the reducer to store state, that's the store's responsibility. You could maybe add a flag that preserves the current functionality, and default it to off in a future release but I would certainly deprecate that functionality as it will cause side effects (such as the issue I've ran into)
How about a reserved hanging method on the reducer:
state() // pure
state.getState() // will return the last-known state to pass through
sounds good, bumped PR with changes
thats correct, it will emit an event labelled "@@REDUX/init" or something similar
Thanks @e-r-w! You rock! I'll get a release out asap.
Currently, when you call
createStore()
with aninitialState
argument, theinitial
object of each State overides theinitialState
passed down from redux. Not sure if this is intentional, but this means that you cannot hydrate the state tree at boot (i.e from localstorage, isomorphic rendering etc).Loving your work though guys! This stuff rocks.