Subjecto is a minimalistic state management library with no dependencies. Its API is inspired from RxJs' Subject.
import { subject } from "subjecto";
// init
const value = new subject(new Date().toISOString())
// subscribe
const handler = value.subscribe((newValue) => {
console.log("subscription 1", newValue);
});
// optionally, set debug to true to see all listeners and value updates
value.debug = true;
// push a new value
value.next(new Date().toISOString());
// get handlers uid
console.log(handler.id);
// unsubscribe
handler.unsubscribe();
// flush all subscriptions
value.complete();
https://codesandbox.io/s/distracted-meadow-vsqwd?file=/src/index.ts
MIT