Skip to content

Commit

Permalink
Remove manual serialization of payload. (#4525)
Browse files Browse the repository at this point in the history
* Remove manual serialization of payload. 

Remove manual serialization of payload using JSON.stringify since it is default serializer.

* Update src/internal/observable/dom/webSocket.ts

Co-Authored-By: aerojeyenth <aerojeyenth@gmail.com>

* Update src/internal/observable/dom/webSocket.ts

Co-Authored-By: aerojeyenth <aerojeyenth@gmail.com>

* Update src/internal/observable/dom/webSocket.ts

Co-Authored-By: aerojeyenth <aerojeyenth@gmail.com>
  • Loading branch information
aerojeyenth authored and benlesh committed May 9, 2019
1 parent 587cb7c commit 66148cb
Showing 1 changed file with 7 additions and 7 deletions.
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

0 comments on commit 66148cb

Please sign in to comment.