Skip to content

Commit

Permalink
fix(multicast): Ensure ConnectableObservables returned by multicast a…
Browse files Browse the repository at this point in the history
…re state-isolated.

This fix ensures ConnectableObservables created by multicast start with null _subject, _connection,
and 0 _refCount.

#2401
  • Loading branch information
trxcllnt committed Feb 23, 2017
1 parent 023d436 commit aaa9e6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/operators/multicast-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ describe('Observable.prototype.multicast', () => {
connectable.connect();
});

it('should multicast a ConnectableObservable', (done: MochaDone) => {
const expected = [1, 2, 3, 4];

const source = new Subject<number>();
const connectable = source.multicast(new Subject<number>());
const replayed = connectable.multicast(new ReplaySubject<number>());

connectable.connect();
replayed.connect();

source.next(1);
source.next(2);
source.next(3);
source.next(4);
source.complete();

replayed.do({
next(x: number) {
expect(x).to.equal(expected.shift());
},
complete() {
expect(expected.length).to.equal(0);
}
})
.subscribe(null, done, done);
});

it('should accept Subject factory functions', (done: MochaDone) => {
const expected = [1, 2, 3, 4];

Expand Down
2 changes: 2 additions & 0 deletions src/observable/ConnectableObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class ConnectableObservable<T> extends Observable<T> {
export const connectableObservableDescriptor: PropertyDescriptorMap = {
operator: { value: null },
_refCount: { value: 0, writable: true },
_subject: { value: null, writable: true },
_connection: { value: null, writable: true },
_subscribe: { value: (<any> ConnectableObservable.prototype)._subscribe },
getSubject: { value: (<any> ConnectableObservable.prototype).getSubject },
connect: { value: (<any> ConnectableObservable.prototype).connect },
Expand Down

0 comments on commit aaa9e6b

Please sign in to comment.