@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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.364latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.364
1.0.350
1.0.340
1.0.330
1.0.320
1.0.300
1.0.291
1.0.281
1.0.271
1.0.261
1.0.251
1.0.240
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

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