Skip to content

Commit

Permalink
feat(publishBehavior): add higher-order lettable version of publishBe…
Browse files Browse the repository at this point in the history
…havior
  • Loading branch information
jasonaden committed Aug 28, 2017
1 parent 8ab0914 commit e911aef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/operator/publishBehavior.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Observable } from '../Observable';
import { BehaviorSubject } from '../BehaviorSubject';
import { multicast } from './multicast';
import { ConnectableObservable } from '../observable/ConnectableObservable';
import {publishBehavior as higherOrder } from '../operators/publishBehavior';

/**
* @param value
Expand All @@ -10,5 +9,5 @@ import { ConnectableObservable } from '../observable/ConnectableObservable';
* @owner Observable
*/
export function publishBehavior<T>(this: Observable<T>, value: T): ConnectableObservable<T> {
return multicast.call(this, new BehaviorSubject<T>(value));
return higherOrder(value)(this);
}
1 change: 1 addition & 0 deletions src/operators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export { pairwise } from './pairwise';
export { partition } from './partition';
export { pluck } from './pluck';
export { publish } from './publish';
export { publishBehavior } from './publishBehavior';
export { race } from './race';
export { reduce } from './reduce';
export { refCount } from './refCount';
Expand Down
15 changes: 15 additions & 0 deletions src/operators/publishBehavior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Observable } from '../Observable';
import { BehaviorSubject } from '../BehaviorSubject';
import { multicast } from './multicast';
import { ConnectableObservable } from '../observable/ConnectableObservable';
import { UnaryFunction } from '../interfaces';

/**
* @param value
* @return {ConnectableObservable<T>}
* @method publishBehavior
* @owner Observable
*/
export function publishBehavior<T>(value: T): UnaryFunction<Observable<T>, ConnectableObservable<T>> {
return (source: Observable<T>) => multicast(new BehaviorSubject<T>(value))(source) as ConnectableObservable<T>;
}

0 comments on commit e911aef

Please sign in to comment.