-
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(shareReplay): add config parameter (#4059)
* test(shareReplay): add failing/conflicting test * feat(shareReplay): add config parameter Closes #3336 * chore(shareReplay): use config for all parameters * chore(shareReplay): deprecate non-config signature * chore(shareReplay): add compat signature * test(dtslint): add shareReplay * chore(shareReplay): undeprecate signature * test(shareReplay): use marble tests * chore(shareReplay): remove compat deprecation
- Loading branch information
Showing
6 changed files
with
99 additions
and
47 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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { Observable, SchedulerLike } from 'rxjs'; | ||
import { shareReplay as higherOrder } from 'rxjs/operators'; | ||
import { ShareReplayConfig } from 'rxjs/internal-compatibility'; | ||
|
||
/** | ||
* @method shareReplay | ||
* @owner Observable | ||
*/ | ||
export function shareReplay<T>(this: Observable<T>, bufferSize?: number, windowTime?: number, scheduler?: SchedulerLike): | ||
export function shareReplay<T>(this: Observable<T>, config: ShareReplayConfig): Observable<T>; | ||
export function shareReplay<T>(this: Observable<T>, bufferSize?: number, windowTime?: number, scheduler?: SchedulerLike): Observable<T>; | ||
export function shareReplay<T>(this: Observable<T>, configOrBufferSize?: ShareReplayConfig | number, windowTime?: number, scheduler?: SchedulerLike): | ||
Observable<T> { | ||
return higherOrder(bufferSize, windowTime, scheduler)(this) as Observable<T>; | ||
if (configOrBufferSize && typeof configOrBufferSize === 'object') { | ||
return higherOrder(configOrBufferSize as ShareReplayConfig)(this) as Observable<T>; | ||
} | ||
return higherOrder(configOrBufferSize as number | undefined, windowTime, scheduler)(this) as Observable<T>; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import { of, asyncScheduler } from 'rxjs'; | ||
import { of, asyncScheduler } from 'rxjs'; | ||
import { shareReplay } from 'rxjs/operators'; | ||
|
||
it('should infer correctly', () => { | ||
const o = of('foo', 'bar', 'baz').pipe(shareReplay()); // $ExpectType Observable<string> | ||
it('should accept an individual bufferSize parameter', () => { | ||
const o = of(1, 2, 3).pipe(shareReplay(1)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support a bufferSize', () => { | ||
const o = of('foo', 'bar', 'baz').pipe(shareReplay(6)); // $ExpectType Observable<string> | ||
it('should accept individual bufferSize and windowTime parameters', () => { | ||
const o = of(1, 2, 3).pipe(shareReplay(1, 2)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support a windowTime', () => { | ||
const o = of('foo', 'bar', 'baz').pipe(shareReplay(6, 4)); // $ExpectType Observable<string> | ||
it('should accept individual bufferSize, windowTime and scheduler parameters', () => { | ||
const o3 = of(1, 2, 3).pipe(shareReplay(1, 2, asyncScheduler)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should support a scheduler', () => { | ||
const o = of('foo', 'bar', 'baz').pipe(shareReplay(6, 4, asyncScheduler)); // $ExpectType Observable<string> | ||
it('should accept a bufferSize config parameter', () => { | ||
const o = of(1, 2, 3).pipe(shareReplay({ bufferSize: 1, refCount: true })); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should enforce type of bufferSize', () => { | ||
const o = of('foo', 'bar', 'baz').pipe(shareReplay('abc')); // $ExpectError | ||
it('should accept bufferSize and windowTime config parameters', () => { | ||
const o = of(1, 2, 3).pipe(shareReplay({ bufferSize: 1, windowTime: 2, refCount: true })); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should enforce type of windowTime', () => { | ||
const o = of('foo', 'bar', 'baz').pipe(shareReplay(5, 'abc')); // $ExpectError | ||
it('should accept bufferSize, windowTime and scheduler config parameters', () => { | ||
const o = of(1, 2, 3).pipe(shareReplay({ bufferSize: 1, windowTime: 2, scheduler: asyncScheduler, refCount: true })); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should enforce type of scheduler', () => { | ||
const o = of('foo', 'bar', 'baz').pipe(shareReplay(5, 3, 'abc')); // $ExpectError | ||
it('should require a refCount config parameter', () => { | ||
const o = of(1, 2, 3).pipe(shareReplay({ bufferSize: 1 })); // $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
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