DELAPARRA
Index
Color
NL
Category: Programming paradigms

Subject

Explained by Updated

What is Subject?

Subject: Both an observable and an observer — it can receive values (next()) and emit them to all subscribers. Used as a bridge between non-reactive and reactive code. In reactive programming, a Subject is both an Observable and an Observer. You can push values into it with next(), and every subscriber receives them.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Subject

How is Subject used in practice?

That makes it a bridge between ordinary code and reactive streams. A button handler or a WebSocket callback can call subject.next(value), and the rest of the application listens to the stream.

What should you keep in mind with Subject?

RxJS offers several variants. A BehaviorSubject remembers the latest value and gives it to new subscribers immediately, which is handy for current state like the logged-in user. A ReplaySubject replays several past values. Subjects are easy to overuse; exposing them publicly lets any code push values. A common pattern is to keep the subject private and expose only the read-only observable to the rest of the code.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with S

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.