Skip to content

Commit

Permalink
docs(webSocket): added more info for multiplex() method (#4529)
Browse files Browse the repository at this point in the history
Removed ambiguous explaination of the messageFilter function

#2193
  • Loading branch information
inf3cti0n95 authored and benlesh committed Feb 5, 2019
1 parent b74b1c0 commit 0d7d123
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/internal/observable/dom/webSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject';
* might stop sending messages, since it got unsubscription message. This needs to be handled
* on the server or using {@link publish} on a Observable returned from 'multiplex'.
*
* Last argument to `multiplex` is a `messageFilter` function which filters out messages
* Last argument to `multiplex` is a `messageFilter` function which should return a boolean. It is used to filter out messages
* sent by the server to only those that belong to simulated WebSocket stream. For example, server might mark these
* messages with some kind of string identifier on a message object and `messageFilter` would return `true`
* if there is such identifier on an object emitted by the socket.
* if there is such identifier on an object emitted by the socket. Messages which returns `false` in `messageFilter` are simply skipped,
* and are not passed down the stream.
*
* Return value of `multiplex` is an Observable with messages incoming from emulated socket connection. Note that this
* is not a `WebSocketSubject`, so calling `next` or `multiplex` again will fail. For pushing values to the
Expand Down Expand Up @@ -120,7 +121,7 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject';
* const observableA = subject.multiplex(
* () => JSON.stringify({subscribe: 'A'}), // When server gets this message, it will start sending messages for 'A'...
* () => JSON.stringify({unsubscribe: 'A'}), // ...and when gets this one, it will stop.
* message => message.type === 'A' // Server will tag all messages for 'A' with type property.
* message => message.type === 'A' // If the function returns `true` message is passed down the stream. Skipped if the function returns false.
* );
*
* const observableB = subject.multiplex( // And the same goes for 'B'.
Expand Down

0 comments on commit 0d7d123

Please sign in to comment.