DEV Community

w3bwizart
w3bwizart

Posted on

2

Using an Singleton with Observer Pattern to manage State?

A general question, I created a Singleton which will use an Observer Pattern where the Singleton becomes the Subject. And every Web Component in my app could become an Observer.

What is Pro/Con here? The main issue I found is that with Pub/Sub the Subject & Observer are loose coupled and work over messages. But is it so bad to use the Observer pattern in a Single Page app in a way everything should be together no?

I wonder what you people think of this? And no I don't want to use Redux or NGRX or any other library.

Looking forward to your feedback or comments.

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay