-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(switchScan): add switchScan() operator (#4442)
* feat(switchScan): add switchScan operator * refactor(switchScan): Make switchScan behavior more close to `scan()` Closes #2931 * docs(switchScan): add link switchScan marble diagram into its docblock * test(switchScan): revert running only switchScan spec * fix(switchScan): fix overriding the same seed for multiple observers * docs(switchScan): fix typo * refactor(switchScan): make seed mandatory as in mergeScan * fix(switchScan): fix typings for union types, remove duplicate dts test * test(switchScan): fix types after rebase to master * refactor(switchScan): use `operate` and `switchMap`. * chore: update golden files * chore: address comments Co-authored-by: Ben Lesh <[email protected]>
- Loading branch information
Showing
10 changed files
with
499 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { of } from 'rxjs'; | ||
import { switchScan } from 'rxjs/operators'; | ||
|
||
it('should infer correctly', () => { | ||
const o = of(1, 2, 3).pipe(switchScan((acc: boolean, v: number) => of(Boolean(v)), false)); // $ExpectType Observable<boolean> | ||
}); | ||
|
||
it('should infer correctly when using a single type', () => { | ||
const o = of(1, 2, 3).pipe(switchScan((acc, v) => of(acc + v), 0)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should infer correctly when using seed of a different type', () => { | ||
const o = of(1, 2, 3).pipe(switchScan((acc, v) => of(acc + v), '0')); // $ExpectType Observable<string> | ||
}); | ||
|
||
it('should support a projector that takes an index', () => { | ||
const o = of(1, 2, 3).pipe(switchScan((acc, v, index) => of(Boolean(v)), false)); // $ExpectType Observable<boolean> | ||
}); | ||
|
||
it('should support projecting to union types', () => { | ||
const o = of(Math.random()).pipe(switchScan(n => n > 0.5 ? of(123) : of('test'), 0)); // $ExpectType Observable<string | number> | ||
}); | ||
|
||
it('should use the inferred accumulator return type over the seed type', () => { | ||
const o = of(1, 2, 3).pipe(switchScan(p => of(1), [])); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should enforce types', () => { | ||
const o = of(1, 2, 3).pipe(switchScan()); // $ExpectError | ||
}); | ||
|
||
it('should enforce the return type to be Observable', () => { | ||
const o = of(1, 2, 3).pipe(switchScan(p => p)); // $ExpectError | ||
}); | ||
|
||
it('should enforce seed and accumulator to have the same type', () => { | ||
const o = of(1, 2, 3).pipe(switchScan((acc, p) => of([...acc, p]))); // $ExpectError | ||
}); |
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.