-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add smarter type inference for ofType pipe.
It is based on TS2.8 introduced conditional types. Upgrade package.json to that version. Move previous version of actions.ts to @ngrx/effects/compat module. Also remove the deprecated non-pipable version of `ofType` so that we don't have to keep complicated types in two places. Fixes some tests post removal of non-pipable version. Original implementation by @mtaran-google.
- Loading branch information
Showing
11 changed files
with
17,323 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
exports_files(["package.json"]) | ||
|
||
load("//tools:defaults.bzl", "ng_module") | ||
|
||
ng_module( | ||
name = "compat", | ||
srcs = glob([ | ||
"src/actions.ts", | ||
]), | ||
module_name = "@ngrx/effects/compat", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//modules/store", | ||
"@rxjs", | ||
"@rxjs//operators", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "@ngrx/effects/compat" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
entry: './dist/effects/@ngrx/effects/compat.es5.js', | ||
dest: './dist/effects/bundles/effects-compat.umd.js', | ||
format: 'umd', | ||
exports: 'named', | ||
moduleName: 'ngrx.effects.compat', | ||
globals: { | ||
'@angular/core': 'ng.core', | ||
'@ngrx/effects': 'ngrx.effects', | ||
'rxjs': 'Rx', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { Action, ScannedActionsSubject } from '@ngrx/store'; | ||
import { Observable, Operator, OperatorFunction } from 'rxjs'; | ||
import { filter } from 'rxjs/operators'; | ||
|
||
@Injectable() | ||
export class Actions<V = Action> extends Observable<V> { | ||
constructor(@Inject(ScannedActionsSubject) source?: Observable<V>) { | ||
super(); | ||
|
||
if (source) { | ||
this.source = source; | ||
} | ||
} | ||
|
||
lift<R>(operator: Operator<V, R>): Observable<R> { | ||
const observable = new Actions<R>(); | ||
observable.source = this; | ||
observable.operator = operator; | ||
return observable; | ||
} | ||
|
||
ofType<V2 extends V = V>(...allowedTypes: string[]): Actions<V2> { | ||
return ofType<any>(...allowedTypes)(this as Actions<any>) as Actions<V2>; | ||
} | ||
} | ||
|
||
export function ofType<T extends Action>( | ||
...allowedTypes: string[] | ||
): OperatorFunction<Action, T> { | ||
return filter((action: Action): action is T => | ||
allowedTypes.some(type => type === action.type) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "../tsconfig-build", | ||
"compilerOptions": { | ||
"paths": { | ||
"@ngrx/store": ["../../dist/packages/store"], | ||
"@ngrx/effects": ["../../dist/packages/effects"] | ||
} | ||
}, | ||
"files": ["index.ts"], | ||
"angularCompilerOptions": { | ||
// Work around for issue: https://github.com/angular/angular/issues/22210 | ||
"strictMetadataEmit": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.