Closed bpetetot closed 5 years ago
init
parameter (given to createStore
) ?defaultData
from k-redux-factory reducers ?Right now I think about:
@@krml/RESET${path ? '>' : ''}${path}
for custom reducers and reactionsreset
in the tree when reducers are from k-redux-factory
, but I don't know if I keep the store declaration at runtime (after the store is created)For me initial store, means the state of the store when I have started it for the first times.
The equivalent in redux is calling each reducers with an undefined state and an empty action. (acting like redux executing them for the first time.)
I am speaking about redux behaviour.
If you pass an initState to redux, I believe it inject that initial state on each subreducer at init (not always valued undefined
)
This is the reason of my question
Ok so, I think I waiting to have the given initial state. (like redux do when it starts for the first time)
path
parameterdescription
of the store (so we can know if a path is a an object description, or a function (reducer))createStore((), { init })
parameter (init
) for the same path
b. if this is a krf
reducer, calls reset
-> 🚧 we have to accept a state into reset payload on krf
🚧
b)bis. if this is a custom reducer, calls ??? 🆘 b) bis. execute the custom reducer with the init
for the same path : custom(init, {})
and I think it's could be the same with krf
reducers.
How do you mutate the redux store ? :)
This is not as easy as you say.
Maybe we have to pass by an enhancer
Of course, it's not as easy as I say 😄
But... maybe we could try to use replaceReducer doing something like that :
store.replaceReducer(combine(store[pathInReducerTree]))
Yes maybe, I don't really know how it behave. Is it synchronous ? In this case this is ok for me. Is it asynchronous ? In this case, how Redux handles action meanwhile reducer is being replaced ?
For me, redux is always synchronous.
I tried but replaceReducer
doesn't work as I expected.
If the reducer already exists, it doesn't seems to update it :(
Mouahaha
➜ k-ramel git:(master) ✗ node reset.js
Data
{ data:
{ nested: { input: 'example' },
shows: { data: [Array], initialized: true } },
ui: true }
reset "ui"
{ data:
{ nested: { input: 'example' },
shows: { data: [Array], initialized: true } },
ui: false }
Data
{ data:
{ nested: { input: 'example' },
shows: { data: [Array], initialized: true } },
ui: true }
reset ""
{ data:
{ nested: { input: '' },
shows: { data: [], initialized: false } },
ui: false }
Data
{ data:
{ nested: { input: 'example' },
shows: { data: [Array], initialized: true } },
ui: true }
reset "data.nested"
{ data:
{ nested: { input: '' },
shows: { data: [Array], initialized: true } },
ui: true }
➜ k-ramel git:(master) ✗
In different use cases, sometimes, I need to reset the store or a part of the store.
For example, when I switch from a connected user to another I need to reset a huge part of the store and its quite exhaustive to do. Because I have to call each
reset()
methods of my reducers, or createRESET
actions to my custom reducers. And, in the future, if I have to add a new reducer, I dont must forget to reset it when needed.I was thinking about a method :
store.reset()
: apply the initial state to the entire storestore.reset('path')
: apply the initial state from the given path