Skip to content

Commit 684728c

Browse files
committed
feat(publishLast): add higher-order lettable version of publishLast
1 parent 0429a69 commit 684728c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/operator/publishLast.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { Observable } from '../Observable';
2-
import { AsyncSubject } from '../AsyncSubject';
3-
import { multicast } from './multicast';
42
import { ConnectableObservable } from '../observable/ConnectableObservable';
5-
3+
import { publishLast as higherOrder } from '../operators';
64
/**
75
* @return {ConnectableObservable<T>}
86
* @method publishLast
97
* @owner Observable
108
*/
119
export function publishLast<T>(this: Observable<T>): ConnectableObservable<T> {
12-
return multicast.call(this, new AsyncSubject<T>());
10+
//TODO(benlesh): correct type-flow through here.
11+
return higherOrder()(this) as ConnectableObservable<T>;
1312
}

src/operators/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export { partition } from './partition';
5454
export { pluck } from './pluck';
5555
export { publish } from './publish';
5656
export { publishBehavior } from './publishBehavior';
57+
export { publishLast } from './publishLast';
5758
export { race } from './race';
5859
export { reduce } from './reduce';
5960
export { refCount } from './refCount';

src/operators/publishLast.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Observable } from '../Observable';
2+
import { AsyncSubject } from '../AsyncSubject';
3+
import { multicast } from './multicast';
4+
import { OperatorFunction } from '../interfaces';
5+
6+
//TODO(benlesh): specify that the second type is actually a ConnectableObservable
7+
export function publishLast<T>(): OperatorFunction<T, T> {
8+
return (source: Observable<T>) => multicast(new AsyncSubject<T>())(source);
9+
}

0 commit comments

Comments
 (0)