Skip to content

Commit d5e1814

Browse files
brandonrobertsMikeRyanDev
authored andcommitted
feat(Effects): Add lettable ofType operator
Introduces lettable operator for Actions.ofType. BREAKING CHANGE: Updates minimum version of RxJS dependency. BEFORE: Minimum peer dependency of RxJS ^5.0.0 AFTER: Minimum peer dependency of RxJS ^5.5.0
1 parent caf6c8d commit d5e1814

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

modules/effects/spec/actions.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
ScannedActionsSubject,
1010
ActionsSubject,
1111
} from '@ngrx/store';
12-
import { Actions } from '../';
12+
import { Actions, ofType } from '../';
13+
import { map, toArray } from 'rxjs/operators';
1314

1415
describe('Actions', function() {
1516
let actions$: Actions;
@@ -64,9 +65,7 @@ describe('Actions', function() {
6465
const expected = actions.filter(type => type === ADD);
6566

6667
actions$
67-
.ofType(ADD)
68-
.map(update => update.type)
69-
.toArray()
68+
.pipe(ofType(ADD), map(update => update.type), toArray())
7069
.subscribe({
7170
next(actual) {
7271
expect(actual).toEqual(expected);

modules/effects/src/actions.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Action, ScannedActionsSubject } from '@ngrx/store';
33
import { Observable } from 'rxjs/Observable';
44
import { Operator } from 'rxjs/Operator';
55
import { filter } from 'rxjs/operator/filter';
6+
import { OperatorFunction } from 'rxjs/interfaces';
67

78
@Injectable()
89
export class Actions<V = Action> extends Observable<V> {
@@ -22,8 +23,14 @@ export class Actions<V = Action> extends Observable<V> {
2223
}
2324

2425
ofType<V2 extends V = V>(...allowedTypes: string[]): Actions<V2> {
25-
return filter.call(this, (action: Action) =>
26+
return ofType<any>(...allowedTypes)(this.source as Actions<V2>);
27+
}
28+
}
29+
30+
export function ofType<T extends Action>(...allowedTypes: string[]) {
31+
return function ofTypeOperator(source$: Actions<T>): Actions<T> {
32+
return filter.call(source$, (action: Action) =>
2633
allowedTypes.some(type => type === action.type)
2734
);
28-
}
35+
};
2936
}

modules/effects/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export {
44
getEffectsMetadata,
55
} from './effects_metadata';
66
export { mergeEffects } from './effects_resolver';
7-
export { Actions } from './actions';
7+
export { Actions, ofType } from './actions';
88
export { EffectsModule } from './effects_module';
99
export { EffectSources } from './effect_sources';
1010
export { OnRunEffects } from './on_run_effects';

0 commit comments

Comments
 (0)