NGRX 效果触发所有动作,但一些
NGRX Effect trigger for all actions but some
我创建了一个控制会话时间的效果。在调用注销操作的时间之后。在我的应用程序中,有一些池可以更新我想忽略的计数器。我该怎么办?
应用程序太大,无法列出所有操作。
@Injectable()
export class ApplicationEffects {
APPLICATION_TIMEOUT_TIME = 1000 * 5;
@Effect()
extendApplicationTimeout$ = createEffect(() => this.actions$
.switchMap( ( action: Action ) => Observable.timer(this.APPLICATION_TIMEOUT_TIME) )
.map(() => new ApplicationActions.LogOut()));
constructor( private actions$: Actions ) {}
}
没试过,但看了 ofType 的代码。您或许可以基于此创建自己的运算符。像这样:
export function ofAnyTypeExcept(...disAllowedTypes: Array<string | ActionCreator<string, Creator>>): OperatorFunction<Action, Action> {
return filter((action: Action) =>
disAllowedTypes.every((typeOrActionCreator) => {
if (typeof typeOrActionCreator === 'string') {
// Comparing the string to type
return typeOrActionCreator !== action.type;
}
// We are filtering by ActionCreator
return typeOrActionCreator.type !== action.type;
})
);
我创建了一个控制会话时间的效果。在调用注销操作的时间之后。在我的应用程序中,有一些池可以更新我想忽略的计数器。我该怎么办?
应用程序太大,无法列出所有操作。
@Injectable()
export class ApplicationEffects {
APPLICATION_TIMEOUT_TIME = 1000 * 5;
@Effect()
extendApplicationTimeout$ = createEffect(() => this.actions$
.switchMap( ( action: Action ) => Observable.timer(this.APPLICATION_TIMEOUT_TIME) )
.map(() => new ApplicationActions.LogOut()));
constructor( private actions$: Actions ) {}
}
没试过,但看了 ofType 的代码。您或许可以基于此创建自己的运算符。像这样:
export function ofAnyTypeExcept(...disAllowedTypes: Array<string | ActionCreator<string, Creator>>): OperatorFunction<Action, Action> {
return filter((action: Action) =>
disAllowedTypes.every((typeOrActionCreator) => {
if (typeof typeOrActionCreator === 'string') {
// Comparing the string to type
return typeOrActionCreator !== action.type;
}
// We are filtering by ActionCreator
return typeOrActionCreator.type !== action.type;
})
);