如何让我的 ngrx/store 效果派发一个空 Action ?我正在运行 Angular 6/rxjs 6:
@Effect()
testEffect$ = this.actions$.ofType(FIRST_ACTION).pipe(
map((x) => {
if (x === y) {
return new SECOND_ACTION;
} else {
fire.some.effect;
return EMPTY;
}
})
);
目前,我收到两个错误:Effect "testEffect$"dispatched an invalid action: [object Object]
后跟 TypeError: Actions must have a type property
.
我找到了 this answer ,但它似乎不适用于 ng/rxjs 6。到目前为止,我已经尝试了以下方法(无效):
EMPTY
、Observable.empty()
、Observable.of()
和 Observable.of([])
,{ 类型:'EMPTY_ACTION' }
任何帮助将不胜感激!我知道我可以使用 { dispatch: false }
,但实际效果有大约五个结果,其中只有一个不使用 Action ,所以我宁愿让最后一个返回一些东西好吧。
最佳答案
这里有一个可能的解决方案:
@Effect()
testEffect$ = this.actions$.ofType(FIRST_ACTION).pipe(
tap((x) => { // do some side effect here
if (x !== y ) {
fire.some.effect;
}
}),
filter((x) => x === y), // proceed only if condition is true
map((x) => {
return new SECOND_ACTION; // then return the needed action
})
);
关于angular - ngrx 效果 : Dispatch Empty Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50833751/