Comments (6)
yep agree, I am not saying the implemention you are using is wrong, for me is NOT just ideal. :)
I dont see any problem why the state should not be passing through store initialState (this is the reason they added this prop in there) - bottom line is, the store is just a "distributor" of state in this case, there is nothing wrong on fact you will pass initial state which may or may not be used by reducer...
Anyway, the best would be to have ability to pass initial state with withReducers() (or any other similar way as initial state factory).
Thanks in advance.
from redux-tools.
Hey there, the intended usage is the first method you described, which should be working fine (we are using this throughout our internal projects). To make the second method work as well, it is necessary to swap out the combineReducers
implementation for a custom one, see #76.
Could you clarify why you'd need to use the second method instead of the first one?
from redux-tools.
Hey there, the intended usage is the first method you described, which should be working fine (we are using this throughout our internal projects). To make the second method work as well, it is necessary to swap out the
combineReducers
implementation for a custom one, see #76.Could you clarify why you'd need to use the second method instead of the first one?
Can you clarify how to use swap out implementation of combineReducers for this case?
And to clarify why the second usage is wrong... mainly it is because it creates side effects and external dependency which is not testable (without mocks). Dont forget the reducers should be pure functions without any dependencies which is not the case if you use localStorage for initial state in reducer
from redux-tools.
Modification of redux-tools is necessary, see packages/reducers/src/combineReducerEntries.js
.
I think that in the second method you're just replacing a problem with another one (testability and impure reducers compared to features being responsible for their own data). To have it "correct", you'd need to pass the token to the createStore
function, but why should the entire store know about the data source for a dependent reducer?
Another option is to instead have an authentication reducer factory and pass the localStorage
data externally, to avoid mocking (i.e. the reducer factory would accept initial data when injecting). This is IMO the best way to approach this in terms of quality of code.
That being said, redux-tools should not limit you in the way you solve this issue, so #76 should be fixed regardless (still a bug).
from redux-tools.
We use the first method because the side-effect is performed only during initialization, which is IMO fine for reducers (It doesn't cause any issues, it just isn't "clean" according to the documentation and FP principles.).
from redux-tools.
fixed by #86
from redux-tools.
Related Issues (20)
- Action required: Greenkeeper could not be activated 🚨
- add section about view-based state management to docs
- link from react package in docs to repo HOT 1
- provide a clear way to dispatch a global action from a namespaced injectable
- specify peerDependencies manually in react package
- bug: ejecting a decorator will always clean-up state HOT 1
- add ESLint rule for sorting imports (and newlines)
- remove `dist` (unpkg) build in all packages except react
- provide guidelines for using action creators in docs HOT 1
- static namespace in `namespacedConnect` currently overrides all inner decorators
- mention that namespacing multi-instance components within a namespace is fine HOT 1
- add `withNamespaceProvider` to `namespaces-react`
- do not reuse default namespace when feature is set HOT 1
- Unable to inject reducer HOT 6
- WebStorm code-completion doesn't work with most of @redux-tools/react exports HOT 1
- add `makeMetaActionCreator`
- Clean up accion changes state HOT 1
- `preventNamespace` is not exported from react package
- Docs: getStateByFeatureAndNamespace example bad import
- deprecate actions package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-tools.