A set of tooling that encapsulates an object that acts as both an Observer and Observable.
Automated by JSR.
Automated by .github\workflows\publish.yml.
Run deno task test or deno task test:ci to execute the unit tests via
Deno.
import { Subject } from "@xan/subject";
import { from } from "@xan/observable";
class Authenticator {
readonly #events = new Subject<Event>();
// Hide the Observer from the public API by exposing the Subject as an Observable.
readonly events = from(this.#events);
[Symbol.dispose]() {
this.#events.return(); // Cleanup resources.
}
login() {
// Execute some login logic...
this.#events.next(new Event("login"));
}
logout() {
// Execute some logout logic...
this.#events.next(new Event("logout"));
}
}