Publish/subscribe (pub/sub) is a messaging pattern where publishers emit events and subscribers react to them, without knowing about each other directly. Many state libraries (and event systems) are built on it — a store publishes changes and components subscribe to them.
A minimal pub/sub store
() {
state = initial;
subscribers = ();
{
: state,
() {
state = { ...state, ...next };
subscribers.( (state));
},
() {
subscribers.(fn);
subscribers.(fn);
},
};
}
