Angular NgRx8从操作中销毁值
各位,我想销毁ngrx效果中的动作类型和道具,我一直在思考如何才能做到这一点 我的行动:Angular NgRx8从操作中销毁值,angular,typescript,rxjs,ngrx,Angular,Typescript,Rxjs,Ngrx,各位,我想销毁ngrx效果中的动作类型和道具,我一直在思考如何才能做到这一点 我的行动: export const addTab = createAction( '[SuperUserTabs] add tab', props<{ tab: SuperUserHeaderTab, tabType: TabType }>() ); export const searchCompanyTab = createAction( '[SuperUserTabs] search c
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]) => {
// this object will contain `type` and action payload
const {type, ...payload} = action;
// some logic
console.log(payload)
})
);
==============
旧答案同样有效:
因为您使用的是action creator,它返回一个函数,所以您可以通过type
属性访问action类型,如下所示:
@Effect({ dispatch: false })
addTab$ = this.actions$.pipe(
ofType(
TabsActions.addTab.type,
TabsActions.searchCompanyTab.type,
TabsActions.searchCardholderTab.type
),
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)
})
);
演示:更新了类型为的accept action creator,因此您可以直接使用它:
@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)
})
);
==============
旧答案同样有效:
因为您使用的是action creator,它返回一个函数,所以您可以通过type
属性访问action类型,如下所示:
@Effect({ dispatch: false })
addTab$ = this.actions$.pipe(
ofType(
TabsActions.addTab.type,
TabsActions.searchCompanyTab.type,
TabsActions.searchCardholderTab.type
),
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)
})
);
演示:你的意思是发射一个
destruct
动作或“摧毁一个动作”(不管那意味着什么)?你的意思是发射一个destruct
动作或“摧毁一个动作”(不管那意味着什么)?