Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.
/ notify Public archive

๐Ÿ“ฃ Minimalistic Pub/Sub implementation

License

Notifications You must be signed in to change notification settings

vangware/notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

This repository's code was moved to lou.codes.


Coverage License NPM Version Open Issues

๐Ÿ“ฃ Minimalistic Pub/Sub implementation.

Usage

๐Ÿ“ฆ Node

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

๐Ÿฆ• Deno

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

๐ŸŒŽ Browser

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>

Useful links