Skip to content
This repository was archived by the owner on Jul 8, 2021. It is now read-only.

Working Example ? #35

Open
GheorgheAlin opened this issue Feb 21, 2018 · 5 comments
Open

Working Example ? #35

GheorgheAlin opened this issue Feb 21, 2018 · 5 comments

Comments

@GheorgheAlin
Copy link

Could we please have a working example with effects and selectors ?

@RobCannon
Copy link

Yes, please. I am running into trouble with setting up the modules for the AppModule and each of my Store module. It would be good to see all of the @NgModule bits need to wire everything up.

@RobCannon
Copy link

RobCannon commented Mar 5, 2018

Here is what I had to use to get this working. I am hoping that there is a way to reduce some of this. The reducers and metareducers seem like they are duplicating some of what NgrxActionsModule.forRoot should do, but I found it was needed to get things to work. Perhaps there is a better way.

BUT, I do love that I can combine my @actions and @effects into one class. It helps to not have to jump to several files just to handle one user action. I would like to see a way to create one file that would combine the actions, effects and actions classes for one user action into one place.

This is from my app.module.ts:

export interface AppState {
  order: OrderStore;
}

export const reducers: ActionReducerMap<AppState> = { order: null };

export const metaReducers: MetaReducer<AppState>[] = !environment.production ? [storeFreeze] : [];

@NgModule({
  declarations: [AppComponent, TopMenuComponent],
  imports: [
    CommonModule,
    BrowserModule,
    BrowserAnimationsModule,
    HttpModule,
    HttpClientModule,
    AppRoutingModule,
    OrderModule,
    StoreModule.forRoot(reducers, { metaReducers }),
    NgrxActionsModule.forRoot({
      order: OrderStore
    }),
    !environment.production ? StoreDevtoolsModule.instrument() : []
  ],
  bootstrap: [AppComponent]
})

And here is an excerpt from my order.module.ts:

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    RouterModule.forChild(routes),
    NgrxActionsModule.forFeature({ order: OrderStore })
  ],
  declarations: [
    OrderPageComponent,
    OrderListComponent
  ],
  providers: [OrderStore, OrderService],
  exports: [RouterModule]
})

I hope that helps.

@lanovoy
Copy link

lanovoy commented Mar 6, 2018

@RobCannon you actually do not need to pass any reducers into forRoot of the StoreModule import. This works just fine: StoreModule.forRoot([])

@RobCannon
Copy link

@lanovoy Thanks! One slight change to support store freeze:

    StoreModule.forRoot({}, { metaReducers: !environment.production ? [storeFreeze] : [] }),
    NgrxActionsModule.forRoot({
      order: OrderStore
    }),
    !environment.production ? StoreDevtoolsModule.instrument() : []

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@RobCannon @lanovoy @GheorgheAlin and others