File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 9
9
ScannedActionsSubject ,
10
10
ActionsSubject ,
11
11
} from '@ngrx/store' ;
12
- import { Actions } from '../' ;
12
+ import { Actions , ofType } from '../' ;
13
+ import { map , toArray } from 'rxjs/operators' ;
13
14
14
15
describe ( 'Actions' , function ( ) {
15
16
let actions$ : Actions ;
@@ -64,9 +65,7 @@ describe('Actions', function() {
64
65
const expected = actions . filter ( type => type === ADD ) ;
65
66
66
67
actions$
67
- . ofType ( ADD )
68
- . map ( update => update . type )
69
- . toArray ( )
68
+ . pipe ( ofType ( ADD ) , map ( update => update . type ) , toArray ( ) )
70
69
. subscribe ( {
71
70
next ( actual ) {
72
71
expect ( actual ) . toEqual ( expected ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Action, ScannedActionsSubject } from '@ngrx/store';
3
3
import { Observable } from 'rxjs/Observable' ;
4
4
import { Operator } from 'rxjs/Operator' ;
5
5
import { filter } from 'rxjs/operator/filter' ;
6
+ import { OperatorFunction } from 'rxjs/interfaces' ;
6
7
7
8
@Injectable ( )
8
9
export class Actions < V = Action > extends Observable < V > {
@@ -22,8 +23,14 @@ export class Actions<V = Action> extends Observable<V> {
22
23
}
23
24
24
25
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 ) =>
26
33
allowedTypes . some ( type => type === action . type )
27
34
) ;
28
- }
35
+ } ;
29
36
}
Original file line number Diff line number Diff line change 4
4
getEffectsMetadata ,
5
5
} from './effects_metadata' ;
6
6
export { mergeEffects } from './effects_resolver' ;
7
- export { Actions } from './actions' ;
7
+ export { Actions , ofType } from './actions' ;
8
8
export { EffectsModule } from './effects_module' ;
9
9
export { EffectSources } from './effect_sources' ;
10
10
export { OnRunEffects } from './on_run_effects' ;
You can’t perform that action at this time.
0 commit comments