diff --git a/modules/effects/spec/actions.spec.ts b/modules/effects/spec/actions.spec.ts index 37250d3d96..1009a138f8 100644 --- a/modules/effects/spec/actions.spec.ts +++ b/modules/effects/spec/actions.spec.ts @@ -9,7 +9,8 @@ import { ScannedActionsSubject, ActionsSubject, } from '@ngrx/store'; -import { Actions } from '../'; +import { Actions, ofType } from '../'; +import { map, toArray } from 'rxjs/operators'; describe('Actions', function() { let actions$: Actions; @@ -64,9 +65,7 @@ describe('Actions', function() { const expected = actions.filter(type => type === ADD); actions$ - .ofType(ADD) - .map(update => update.type) - .toArray() + .pipe(ofType(ADD), map(update => update.type), toArray()) .subscribe({ next(actual) { expect(actual).toEqual(expected); diff --git a/modules/effects/src/actions.ts b/modules/effects/src/actions.ts index 8f779a9802..8c7d1c46e6 100644 --- a/modules/effects/src/actions.ts +++ b/modules/effects/src/actions.ts @@ -3,6 +3,7 @@ import { Action, ScannedActionsSubject } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; import { Operator } from 'rxjs/Operator'; import { filter } from 'rxjs/operator/filter'; +import { OperatorFunction } from 'rxjs/interfaces'; @Injectable() export class Actions extends Observable { @@ -22,8 +23,14 @@ export class Actions extends Observable { } ofType(...allowedTypes: string[]): Actions { - return filter.call(this, (action: Action) => + return ofType(...allowedTypes)(this.source as Actions); + } +} + +export function ofType(...allowedTypes: string[]) { + return function ofTypeOperator(source$: Actions): Actions { + return filter.call(source$, (action: Action) => allowedTypes.some(type => type === action.type) ); - } + }; } diff --git a/modules/effects/src/index.ts b/modules/effects/src/index.ts index bee1e4ff53..ed6868bd77 100644 --- a/modules/effects/src/index.ts +++ b/modules/effects/src/index.ts @@ -4,7 +4,7 @@ export { getEffectsMetadata, } from './effects_metadata'; export { mergeEffects } from './effects_resolver'; -export { Actions } from './actions'; +export { Actions, ofType } from './actions'; export { EffectsModule } from './effects_module'; export { EffectSources } from './effect_sources'; export { OnRunEffects } from './on_run_effects';