Skip to content

Commit

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

import { publishLast as higherOrder } from '../operators';
/**
* @return {ConnectableObservable<T>}
* @method publishLast
* @owner Observable
*/
export function publishLast<T>(this: Observable<T>): ConnectableObservable<T> {
return multicast.call(this, new AsyncSubject<T>());
//TODO(benlesh): correct type-flow through here.
return higherOrder()(this) as ConnectableObservable<T>;
}
1 change: 1 addition & 0 deletions src/operators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export { partition } from './partition';
export { pluck } from './pluck';
export { publish } from './publish';
export { publishBehavior } from './publishBehavior';
export { publishLast } from './publishLast';
export { race } from './race';
export { reduce } from './reduce';
export { refCount } from './refCount';
Expand Down
9 changes: 9 additions & 0 deletions src/operators/publishLast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Observable } from '../Observable';
import { AsyncSubject } from '../AsyncSubject';
import { multicast } from './multicast';
import { OperatorFunction } from '../interfaces';

//TODO(benlesh): specify that the second type is actually a ConnectableObservable
export function publishLast<T>(): OperatorFunction<T, T> {
return (source: Observable<T>) => multicast(new AsyncSubject<T>())(source);
}

0 comments on commit 684728c

Please sign in to comment.