From 40e48332220b359051dae2ffe65c36e27ffc8f1c Mon Sep 17 00:00:00 2001 From: Jeyenthaaran N Date: Fri, 10 May 2019 00:53:56 +0100 Subject: [PATCH] Remove manual serialization of payload. (#4525) * 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 * Update src/internal/observable/dom/webSocket.ts Co-Authored-By: aerojeyenth * Update src/internal/observable/dom/webSocket.ts Co-Authored-By: aerojeyenth --- src/internal/observable/dom/webSocket.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/internal/observable/dom/webSocket.ts b/src/internal/observable/dom/webSocket.ts index c52b714778..e11560748c 100644 --- a/src/internal/observable/dom/webSocket.ts +++ b/src/internal/observable/dom/webSocket.ts @@ -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 @@ -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. * @@ -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' * ); *