DEV Community


Posted on

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)