diff --git a/src/operator/publishBehavior.ts b/src/operator/publishBehavior.ts index eaa9ae295c..dfee6193ed 100644 --- a/src/operator/publishBehavior.ts +++ b/src/operator/publishBehavior.ts @@ -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 @@ -10,5 +9,5 @@ import { ConnectableObservable } from '../observable/ConnectableObservable'; * @owner Observable */ export function publishBehavior(this: Observable, value: T): ConnectableObservable { - return multicast.call(this, new BehaviorSubject(value)); + return higherOrder(value)(this); } diff --git a/src/operators/index.ts b/src/operators/index.ts index 1675425138..1d9ef31314 100644 --- a/src/operators/index.ts +++ b/src/operators/index.ts @@ -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'; diff --git a/src/operators/publishBehavior.ts b/src/operators/publishBehavior.ts new file mode 100644 index 0000000000..0d340ac915 --- /dev/null +++ b/src/operators/publishBehavior.ts @@ -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} + * @method publishBehavior + * @owner Observable + */ +export function publishBehavior(value: T): UnaryFunction, ConnectableObservable> { + return (source: Observable) => multicast(new BehaviorSubject(value))(source) as ConnectableObservable; +}