Skip to main content
Home

Built and signed on GitHub Actions

A lightweight, RxJS-inspired library implementing the Observer pattern in JavaScript. Features BroadcastSubjects with AbortController-based unsubscription, supporting both synchronous and asynchronous producers.

This package works with Node.js, BrowsersIt is unknown whether this package works with Cloudflare Workers, Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
100%
Published
a week ago (0.1.0)

@xan/broadcast-subject

A set of tooling that encapsulates an object that acts as a variant of Subject with the intent to enable the sending of values to other contexts (Browser tabs, iframes, workers, ect.).

Build

Automated by JSR.

Publishing

Automated by .github\workflows\publish.yml.

Running unit tests

Run deno task test or deno task test:ci to execute the unit tests via Deno.

Example

import { BroadcastSubject } from "@xan/broadcast-subject";

// Setup subjects
const name = "test";
const controller = new AbortController();
const subject1 = new BroadcastSubject<number>(name);
const subject2 = new BroadcastSubject<number>(name);

// Subscribe to subjects
subject1.subscribe({
  signal: controller.signal,
  next: (value) => console.log("subject1 received", value, "from subject1"),
  return: () => console.log("subject1 returned"),
  throw: (value) => console.log("subject1 threw", value),
});
subject2.subscribe({
  signal: controller.signal,
  next: (value) => console.log("subject2 received", value, "from subject2"),
  return: () => console.log("subject2 returned"),
  throw: (value) => console.log("subject2 threw", value),
});

subject1.next(1); // subject2 received 1 from subject1
subject2.next(2); // subject1 received 2 from subject2
subject2.return(); // subject2 returned
subject1.next(3); // No console output since subject2 is already returned

Glossary And Semantics

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

pnpm i jsr:@xan/broadcast-subject
or (using pnpm 10.8 or older)
pnpm dlx jsr add @xan/broadcast-subject

Import symbol

import * as broadcast_subject from "@xan/broadcast-subject";

Add Package

yarn add jsr:@xan/broadcast-subject
or (using Yarn 4.8 or older)
yarn dlx jsr add @xan/broadcast-subject

Import symbol

import * as broadcast_subject from "@xan/broadcast-subject";

Add Package

vlt install jsr:@xan/broadcast-subject

Import symbol

import * as broadcast_subject from "@xan/broadcast-subject";

Add Package

npx jsr add @xan/broadcast-subject

Import symbol

import * as broadcast_subject from "@xan/broadcast-subject";

Add Package

bunx jsr add @xan/broadcast-subject

Import symbol

import * as broadcast_subject from "@xan/broadcast-subject";