Sup*_*miu 6 ngrx ngrx-effects angular
I have a simple feature module, which provides services and imports its own stats fragment as a feature:
@NgModule({
imports: [
CommonModule,
StoreModule.forFeature('alarms', alarmsReducer, { initialState: alarmsInitialState }),
EffectsModule.forFeature([AlarmsEffects])
],
declarations: [],
providers: [
AlarmsFacade,
AlarmsService
]
})
export class AlarmsModule {
}
Run Code Online (Sandbox Code Playgroud)
And I'm importing this module in two other modules, a page that needs to have access to the services, and AppModule as I need to import it here in order to have the state initialized properly.
When I'm checking Redux DevTools, I can clearly see that @ngrx/store/update-reducers is called twice for the feature alarms. This results in the state being frozen, stoping all the effects (including the ones not related to alarms feature).
The timeline below can show the issue (a third @ngrx/store/update-reducers action is fired after the effects init while there's only two features at the moment, it contains reducers for feature 'alarms'):
How can I avoid the effects to be loaded twice? I tried to remove the module from AppModule but it's breaking the alarms state as there's no default one provided for my selectors.
Net*_*oke 12
这是我的问题:
升级到 ngrx 8 后,我没有从我过渡到 createEffect 的效果中删除 @Effect() 装饰器。
我从效果中删除了 {dispatch: false} (现在使用 createEffect),而不是将它们作为第二个参数放在箭头函数之后。
另请参阅:使用 StoreDevtoolsModule.instrument() 时,Effect 被调用两次
如果您需要多个模块中的某些状态片段,那么它显然不是功能状态,而是主状态。因此,将该切片移动到主模块中并在那里为其实现减速器/效果。
| 归档时间: |
|
| 查看次数: |
3344 次 |
| 最近记录: |