Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove manual serialization of payload. #4525

Merged
merged 5 commits into from May 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/internal/observable/dom/webSocket.ts
Expand Up @@ -66,7 +66,7 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject';
* subscribes and unsubscribes. Server can use them to verify that some kind of messages should start or stop
* being forwarded to the client. In case of the above example application, after getting subscription message with proper identifier,
* gateway server can decide that it should connect to real sport news service and start forwarding messages from it.
* Note that both messages will be sent as returned by the functions, meaning they will have to be serialized manually, just
* Note that both messages will be sent as returned by the functions, they are by default serialized using JSON.stringify, just
* as messages pushed via `next`. Also bear in mind that these messages will be sent on *every* subscription and
* unsubscription. This is potentially dangerous, because one consumer of an Observable may unsubscribe and the server
* might stop sending messages, since it got unsubscription message. This needs to be handled
Expand Down Expand Up @@ -104,8 +104,8 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject';
* // Note that at least one consumer has to subscribe to the created subject - otherwise "nexted" values will be just buffered and not sent,
* // since no connection was established!
*
* subject.next(JSON.stringify({message: 'some message'}));
* // This will send a message to the server once a connection is made. Remember to serialize sent value first!
* subject.next({message: 'some message'});
* // This will send a message to the server once a connection is made. Remember value is serialized with JSON.stringify by default!
*
* subject.complete(); // Closes the connection.
*
Expand All @@ -119,14 +119,14 @@ import { WebSocketSubject, WebSocketSubjectConfig } from './WebSocketSubject';
* const subject = webSocket('ws://localhost:8081');
*
* 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.
* () => ({subscribe: 'A'}), // When server gets this message, it will start sending messages for 'A'...
* () => ({unsubscribe: 'A'}), // ...and when gets this one, it will stop.
* 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'.
* () => JSON.stringify({subscribe: 'B'}),
* () => JSON.stringify({unsubscribe: 'B'}),
* () => ({subscribe: 'B'}),
* () => ({unsubscribe: 'B'}),
* message => message.type === 'B'
* );
*
Expand Down