@lou.codes/notify
TypeScript icon, indicating that this package has built-in type declarations

1.0.36Β β€’Β PublicΒ β€’Β Published

Coverage License NPM Version Open Issues Size

πŸ“£ 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

Dependencies (5)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @lou.codes/notify

    Weekly Downloads

    9

    Version

    1.0.36

    License

    MIT

    Unpacked Size

    15.7 kB

    Total Files

    19

    Last publish

    Collaborators

    • loucyx