-
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 higher-order lettable version of shareReplay
- Loading branch information
Showing
3 changed files
with
30 additions
and
18 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,26 +1,12 @@ | ||
import { Observable } from '../Observable'; | ||
import { multicast } from './multicast'; | ||
import { ReplaySubject } from '../ReplaySubject'; | ||
import { ConnectableObservable } from '../observable/ConnectableObservable'; | ||
import { IScheduler } from '../Scheduler'; | ||
import { shareReplay as higherOrder } from '../operators/shareReplay'; | ||
|
||
/** | ||
* @method shareReplay | ||
* @owner Observable | ||
*/ | ||
export function shareReplay<T>( | ||
this: Observable<T>, | ||
bufferSize?: number, | ||
windowTime?: number, | ||
scheduler?: IScheduler | ||
): Observable<T> { | ||
let subject: ReplaySubject<T>; | ||
const connectable = multicast.call(this, function shareReplaySubjectFactory(this: ConnectableObservable<T>) { | ||
if (this._isComplete) { | ||
return subject; | ||
} else { | ||
return (subject = new ReplaySubject<T>(bufferSize, windowTime, scheduler)); | ||
} | ||
}); | ||
return connectable.refCount(); | ||
export function shareReplay<T>(this: Observable<T>, bufferSize?: number, windowTime?: number, scheduler?: IScheduler): | ||
Observable<T> { | ||
return higherOrder(bufferSize, windowTime, scheduler)(this); | ||
}; |
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,25 @@ | ||
import { Observable } from '../Observable'; | ||
import { multicast } from './multicast'; | ||
import { refCount } from './refCount'; | ||
import { ReplaySubject } from '../ReplaySubject'; | ||
import { ConnectableObservable } from '../observable/ConnectableObservable'; | ||
import { IScheduler } from '../Scheduler'; | ||
|
||
import { MonoTypeOperatorFunction } from '../interfaces'; | ||
|
||
/** | ||
* @method shareReplay | ||
* @owner Observable | ||
*/ | ||
export function shareReplay<T>(bufferSize?: number, windowTime?: number, scheduler?: IScheduler ): MonoTypeOperatorFunction<T> { | ||
let subject: ReplaySubject<T>; | ||
|
||
const connectable = multicast(function shareReplaySubjectFactory(this: ConnectableObservable<T>) { | ||
if (this._isComplete) { | ||
return subject; | ||
} else { | ||
return (subject = new ReplaySubject<T>(bufferSize, windowTime, scheduler)); | ||
} | ||
}); | ||
return (source: Observable<T>) => refCount()(connectable(source)); | ||
}; |