@lou.codes/notify
v1.0.36
Published
π£ Minimalistic Pub/Sub implementation
Downloads
58
Maintainers
Readme
π£ Minimalistic Pub/Sub implementation.
Usage
π¦ Node
Install @lou.codes/notify
as a dependency:
pnpm add @lou.codes/notify
# or
npm install @lou.codes/notify
# or
yarn add @lou.codes/notify
Import it and use it:
import { broadcast } from "@lou.codes/notify";
const { emit, on } = broadcast<{ event: string }>();
const onEvent = on("event");
const offEvent = onEvent(console.log);
const emitEvent = emit("event");
emitEvent("Hello world 1"); // Logs "Hello world 1"
emitEvent("Hello world 2"); // Logs "Hello world 2"
offEvent();
emitEvent("Nope"); // Nothing happens
π¦ Deno
Import @lou.codes/notify
using the npm:
prefix, and use it directly:
import { broadcast } from "npm:@lou.codes/notify";
const { emit, on } = broadcast<{ event: string }>();
const onEvent = on("event");
const offEvent = onEvent(console.log);
const emitEvent = emit("event");
emitEvent("Hello world 1"); // Logs "Hello world 1"
emitEvent("Hello world 2"); // Logs "Hello world 2"
offEvent();
emitEvent("Nope"); // Nothing happens
π Browser
Import @lou.codes/notify
using esm.sh, and use it directly:
<script type="module">
import { broadcast } from "https://esm.sh/@lou.codes/notify";
const { emit, on } = broadcast();
const onEvent = on("event");
const offEvent = onEvent(console.log);
const emitEvent = emit("event");
emitEvent("Hello world 1"); // Logs "Hello world 1"
emitEvent("Hello world 2"); // Logs "Hello world 2"
offEvent();
emitEvent("Nope"); // Nothing happens
</script>
Useful links
- π Documentation: TypeDoc generated documentation.
- β³ Changelog: List of changes between versions.
- β Tests Coverage: Coveralls page with tests coverage.