NgRx8破坏了行动的价值

时间:2019-09-22 08:38:01

标签: angular typescript rxjs ngrx

每个人,我都想破坏ngrx效果中的动作类型和道具,我陷入了如何做的困境

我的动作:

export const addTab = createAction(
  '[SuperUserTabs] add tab',
  props<{ tab: SuperUserHeaderTab, tabType: TabType }>()
);

export const searchCompanyTab = createAction(
  '[SuperUserTabs] search company tab'
);

export const searchCardholderTab = createAction(
  '[SuperUserTabs] search cardholder tab'
);

效果:

@Effect({ dispatch: false })
  addTab$ = this.actions$.pipe(
    ofType(
      TabsActions.addTab,
      TabsActions.searchCompanyTab,
      TabsActions.searchCardholderTab
    ),
    withLatestFrom(this.store.pipe(select(getTabs))),
    tap(([action, tabs]) => {
      // destruct here 
      const {type, props} = action;
      // some logic
    })
  );

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

已更新└── main.py ├── module1.py ├── func1 ├── module2.py ├── func2 接受动作创建者,因此您可以直接使用它:

ofType

=============== 旧答案也可以:

因为您使用的是操作创建器,该操作创建器返回一个函数,所以您可以通过@Effect({ dispatch: false }) addTab$ = this.actions$.pipe( ofType( TabsActions.addTab, TabsActions.searchCompanyTab, TabsActions.searchCardholderTab ), withLatestFrom(this.store.pipe(select(getTabs))), tap(([action, tabs]) => { // this object will contain `type` and action payload const {type, ...payload} = action; // some logic console.log(payload) }) ); 属性访问操作类型,如下所示:

type

演示:https://stackblitz.com/edit/angular-3t2fmx?file=src%2Fapp%2Fstore.ts