Angular:如何覆盖商店

时间:2021-05-25 18:54:43

标签: angular ngrx ngrx-store spartacus-storefront

我正在为我们的项目使用 Spartacus angular 解决方案,该解决方案已经包含 ngrx 存储以及内部的一组动作、效果和减速器。请指点我如何用我自己的解决方案覆盖部分商店。

如果我没有找到任何关于此的主题,我想我正在尝试做不可能的事情......

一些细节:

<块引用>

文件结构

my-store
  actions
     index.ts
     ...action.ts
  effects
     index.ts
     ...effect.ts
  reducers
     index.ts
     ...reducer.ts
  selectors
     index.ts
     ...selectors.ts
  store.module.ts
<块引用>

store.module.ts

@NgModule({
  imports: [
    CommonModule,
    StoreModule.forFeature(CHECKOUT_FEATURE, reducerToken),
    EffectsModule.forFeature(effects),
  ],
  providers: [reducerProvider],
})
export class CheckoutStoreModule {}
<块引用>

reducers/index.ts

export function getReducers(): ActionReducerMap<CheckoutState> {
  return {
    steps: loaderReducer<CheckoutStepsState>(
      CHECKOUT_DETAILS,
      fromCheckout.reducer
    ),
    cardTypes: fromCardTypes.reducer,
    addressVerification: fromAddressVerification.reducer,
    paymentTypes: fromPaymentTypes.reducer,
    orderType: fromOrderTypes.reducer,
  };
}

export const reducerToken: InjectionToken<
  ActionReducerMap<CheckoutState>
> = new InjectionToken<ActionReducerMap<CheckoutState>>('CheckoutReducers');

export const reducerProvider: Provider = {
  provide: reducerToken,
  useFactory: getReducers,
};

0 个答案:

没有答案