ngoc chau nguyen
ngoc chau nguyen

Reputation: 21

ngrx/store-update-reducers called multiple times

This is my code structure:

app/
├── core/
│ └── app.reducers.ts/
├── app.component.html
├── app.component.ts
├── app.module.ts
├── app-routing.module.ts
├── core/
│ ├── footer/
│ ├── header/
│ ├── core.module.ts
├── auth/
│ ├── signin/
│ ├── signup/
│ ├── store/
│ │ ├── auth.actions.ts
│ │ ├── auth.effects.ts
│ │ ├── auth.reducers.ts
│ ├── auth.module.ts
│ └── services/
├── admin/
│ ├── dashboard/
│ ├── setting/
│ ├── store/
│ │ ├── admin.actions.ts
│ │ ├── admin.effects.ts
│ │ ├── admin.reducers.ts
│ ├── admin-routing.module.ts
│ ├── admin.module.ts
│ └── services/
└── shared/
├── shared.module.ts
├── components/
├── models/
├── components/
├── directives/
└── services/

With the code above, I structured my code with multiple modules and using @ngrx/store library.For each module, I have a store (including: action, reducer, effect). I have one main store at root for managing all stores that are using metareducer (imported from app.module.ts). I am using logger to view each called action or changed state, then logger will show the current state or action in console log.

When the app starts, the console log from the browser showed multiple times that they are called by store.

I don't know why the update-reducers from store is called multiple times.

I expected log message for each module which will only show one time when the module is initialized. I investigated from many source codes which is store all reducer in one place. Is it good for my structure?

Can somebody help me?

Upvotes: 0

Views: 1430

Answers (1)

tilo
tilo

Reputation: 14169

For the record: this has been answered on GitHub:

It's called for each new StoreModule.forFeature that registers a reducer. This has been updated with the next major release to group the registered modules together into one update call.

Upvotes: 1

Related Questions