Skip to content

Commit

Permalink
feat(publishReplay): add higher-order lettable version of publishReplay
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Sep 4, 2017
1 parent 684728c commit 2958917
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/operator/publishReplay.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Observable } from '../Observable';
import { ReplaySubject } from '../ReplaySubject';
import { IScheduler } from '../Scheduler';
import { multicast } from './multicast';
import { ConnectableObservable } from '../observable/ConnectableObservable';
import { publishReplay as higherOrder } from '../operators';

/**
* @param bufferSize
Expand All @@ -15,5 +14,5 @@ import { ConnectableObservable } from '../observable/ConnectableObservable';
export function publishReplay<T>(this: Observable<T>, bufferSize: number = Number.POSITIVE_INFINITY,
windowTime: number = Number.POSITIVE_INFINITY,
scheduler?: IScheduler): ConnectableObservable<T> {
return multicast.call(this, new ReplaySubject<T>(bufferSize, windowTime, scheduler));
return higherOrder(bufferSize, windowTime, scheduler)(this);
}
1 change: 1 addition & 0 deletions src/operators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export { pluck } from './pluck';
export { publish } from './publish';
export { publishBehavior } from './publishBehavior';
export { publishLast } from './publishLast';
export { publishReplay } from './publishReplay';
export { race } from './race';
export { reduce } from './reduce';
export { refCount } from './refCount';
Expand Down
12 changes: 12 additions & 0 deletions src/operators/publishReplay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Observable } from '../Observable';
import { ReplaySubject } from '../ReplaySubject';
import { IScheduler } from '../Scheduler';
import { multicast } from './multicast';
import { ConnectableObservable } from '../observable/ConnectableObservable';
import { UnaryFunction } from '../interfaces';

export function publishReplay<T>(bufferSize: number = Number.POSITIVE_INFINITY,
windowTime: number = Number.POSITIVE_INFINITY,
scheduler?: IScheduler): UnaryFunction<Observable<T>, ConnectableObservable<T>> {
return (source: Observable<T>) => multicast(new ReplaySubject<T>(bufferSize, windowTime, scheduler))(source) as ConnectableObservable<T>;
}

0 comments on commit 2958917

Please sign in to comment.