This repository's code was moved to lou.codes.
๐ฃ Minimalistic Pub/Sub implementation.
Install @vangware/notify
as a dependency:
pnpm add @vangware/notify
# or
npm install @vangware/notify
# or
yarn add @vangware/notify
Import it and use it:
import { broadcast } from "@vangware/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
Import @vangware/notify
using the npm:
prefix, and use it directly:
import { broadcast } from "npm:@vangware/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
Import @vangware/notify
using esm.sh, and use it directly:
<script type="module">
import { broadcast } from "https://esm.sh/@vangware/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
</script>
- ๐ Documentation: TypeDoc generated documentation.
- โณ Changelog: List of changes between versions.
- โ Tests Coverage: Coveralls page with tests coverage.