为什么使用 reducerManager 会给出不正确的状态
我正在使用 reducerManager
在全局对象中添加我的减速器。
例如,如果我写
const reducer = createReducer(initialState, on( doSomething, state => state ) );
则:
reducerManager.addReducer( 'reducer', reducer );
在我的组件中使用 select 我需要编写:
val:Observable
我的问题是为什么我不能只写:
val:Observable
这是使用减速器管理器的含义还是我弄错了?
我已经向我的经理添加了许多减速器,并且在将名称写入状态属性以获得最终值后,我总是得到相同的存储状态(顺便说一句,这些状态是共享的,它的目的是什么?)
I'm using reducerManager
to add my reducers inside of a global object.
if for example I write
const reducer = createReducer( initialState, on( doSomething, state => state ) );
then:
reducerManager.addReducer( 'reducer', reducer );
and in my component use select I need to write:
val:Observable<any> = this.store.select( state => state.reducer.val );
My question is why can't I just write:
val:Observable<any> = this.store.select( state => state.val );
is this the meaning of using a reducer manager or am I getting something wrong?
I've added many reducers to my manager and after writing the name as state property to get my final value, I always get the same store state ( btw do these states are shared, what's the purpose of it ?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
国家是一个全局对象。
通过使用
reducerManager.addReducer('reducer',reducer);
,您可以将reducer添加到全局对象中,并以reducer
为键。因此,您的状态变为
要从存储中读取,您总是从根对象中选择,因此您需要从
reducer
属性中选择状态。The state is a global object.
By using
reducerManager.addReducer( 'reducer', reducer );
you're adding the reducer to the global object, withreducer
as key.So your state becomes
To read from the store you always select from the root object, and thus you need to select the state from the
reducer
property.