Liudas Drejeris
1 min readJul 11, 2023

--

Hi,

first of all, thanks for the questions. Yes, as this is a simple example, all components that are subscribed will receive all incoming messages. To pass only specific messages to the component you must also add a message type to "event.data". Your 'event.data' could look something like: "{ listOfProducts: [], type: 'products' }", then you can filter messages by "type" in your WebSocketService and pass them into different Observables, so your components would subscribe only to the message type they need or pass all messages to one subscription, as it is done in example, and use "filter" operator in your components to filter out only messages the component is using. I would probably leave the service as simple as possible and make the components responsible for filtering messages they need. Also make a "enum" for all message types, for cleaner code. ;) I Hope I answered your questions :) if you need more help, you can write me an email: drejeris.liudas@gmail.com

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Liudas Drejeris
Liudas Drejeris

Written by Liudas Drejeris

Senior Full Stack Developer, Photographer , Gardener and Healthy Lifestyle Enthusiast

Responses (1)

Write a response