Skip to content

Commit

Permalink
fix(WebSocketSubject): WebSocketSubject will now chain operators prop…
Browse files Browse the repository at this point in the history
…erly (#1752)

fixes #1745
  • Loading branch information
benlesh committed Jun 8, 2016
1 parent 60bb00e commit bf54db4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
23 changes: 23 additions & 0 deletions spec/observables/dom/webSocket-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ describe('Observable.webSocket', () => {
subject.unsubscribe();
});

it('should allow the user to chain operators', () => {
let messageReceived = false;
const subject = Observable.webSocket('ws://mysocket');

subject
.map(x => x + '?')
.map(x => x + '!')
.map(x => x + '!')
.subscribe((x: string) => {
expect(x).to.equal('pong?!!');
messageReceived = true;
});

const socket = MockWebSocket.lastSocket;

socket.open();

socket.triggerMessage(JSON.stringify('pong'));
expect(messageReceived).to.be.true;

subject.unsubscribe();
});

it('receive multiple messages', () => {
const expected = ['what', 'do', 'you', 'do', 'with', 'a', 'drunken', 'sailor?'];
const results = [];
Expand Down
7 changes: 0 additions & 7 deletions src/observable/dom/WebSocketSubject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Subject, AnonymousSubject} from '../../Subject';
import {Subscriber} from '../../Subscriber';
import {Observable} from '../../Observable';
import {Operator} from '../../Operator';
import {Subscription} from '../../Subscription';
import {root} from '../../util/root';
import {ReplaySubject} from '../../ReplaySubject';
Expand Down Expand Up @@ -68,12 +67,6 @@ export class WebSocketSubject<T> extends AnonymousSubject<T> {
this.destination = new ReplaySubject();
}

lift<R>(operator: Operator<T, R>) {
const sock: WebSocketSubject<T> = new WebSocketSubject(this, this.destination);
sock.operator = <any>operator;
return sock;
}

// TODO: factor this out to be a proper Operator/Subscriber implementation and eliminate closures
multiplex(subMsg: () => any, unsubMsg: () => any, messageFilter: (value: T) => boolean) {
const self = this;
Expand Down

0 comments on commit bf54db4

Please sign in to comment.