skip to the page

@jam-overture/loom/signals/broadcast

The reader-signal broadcaster alone, for a browser bundle — about 5 KB, with no schema library.

Everything below is exported from that import. The names, the signatures and the sentences are read from the package itself rather than written here, so this page says what the copy of Loom in your node_modules says — and it changes in the same pull request the code does.

15 exports, in 2 modules. Generated from ./dist/signals/broadcast.d.ts, which is the declaration file this package publishes for @jam-overture/loom/signals/broadcast. Each comment inside a declaration is shown as its first paragraph. The whole of it is in that file.

Nothing to install first. Everything this import loads arrives with @jam-overture/loom itself.

No import here has everything behind it. @jam-overture/loom/signals/broadcast publishes 15 of the 2,237 names this package publishes. The other 2,222 are behind one of the 19 other imports, and 18 of those 19 publish nothing this one does. The imports do not nest: a name that is not on this page is not a name that does not exist, and the search at the top of the page says which import it comes from.

Every one of these names is published elsewhere too: 15 by @jam-overture/loom/signals — the same declarations reached through two doors, so either import gives you the same thing.

Broadcast

signals/broadcast

Broadcasting reader signals from a rendered Loom page.

READER_SIGNALS_EVENTvalue

const READER_SIGNALS_EVENT = "loom:signals"

VisibilityObservertype

Something that reports elements coming into and out of view. The browser's IntersectionObserver unless a host passes its own.

type VisibilityObserver = {
    readonly observe: (element: Element) => void;
    readonly disconnect: () => void;
};

VisibilityEntrytype

type VisibilityEntry = {
    readonly target: Element;
    readonly visible: boolean;
};

ObserveVisibilitytype

type ObserveVisibility = (onChange: (entries: readonly VisibilityEntry[]) => void) => VisibilityObserver;

ReaderSignalTypestype

The primitive types to report on: one list for every kind, or a list per kind.

type ReaderSignalTypes = readonly string[] | {
    readonly [Kind in ReaderSignalKind]?: readonly string[];
};

ReaderSignalOptionstype

type ReaderSignalOptions = {
    /** Called with every batch. A throw or rejection here is contained and never reaches the page. */
    readonly send?: (batch: ReaderSignalBatch) => void | Promise<void>;
    /** Which kinds to broadcast. Every kind when absent. */
    readonly kinds?: readonly ReaderSignalKind[];
    /**
     * Which primitive types to broadcast about. Every addressed type when absent.
     */
    readonly types?: ReaderSignalTypes;
    /** How often a batch is delivered. Five seconds when absent. */
    readonly flushEveryMs?: number;
    /**
     * How the broadcaster learns what is on screen. The browser's
     * `IntersectionObserver` when absent; a test passes its own.
     */
    readonly observeVisibility?: ObserveVisibility;
    /**
     * Whether a delegated signal carries the addressed nodes it happened inside.
     * On when absent.
     */
    readonly within?: boolean;
    /** The clock. `Date.now` when absent. */
    readonly now?: () => number;
    /**
     * Where the view key's randomness comes from. The browser's
     * `crypto.getRandomValues` when absent; a test passes its own so it can name
     * the key it expects.
     */
    readonly random?: RandomBytes;
};

ReaderSignalBroadcasttype

type ReaderSignalBroadcast = {
    /** Deliver whatever has been gathered, now. */
    readonly flush: () => void;
    /** Deliver what is left and stop observing. Safe to call twice. */
    readonly stop: () => void;
};

ReaderSignalBroadcastErrortype

type ReaderSignalBroadcastError = {
    /** The root carries no tree id or revision — the page was not rendered with `addressed: true`. */
    readonly code: "unaddressed";
    readonly detail: string;
};

broadcastReaderSignalsfunction

Start broadcasting reader signals from a rendered Loom page.

Shown in use on What your readers do — Two: start the broadcaster, in the browser

const broadcastReaderSignals: (scope: Element | Document, options?: ReaderSignalOptions) => Result<ReaderSignalBroadcast, ReaderSignalBroadcastError>

Deliver

signals/deliver

Getting a batch off the page.

DEFAULT_READER_SIGNAL_PATHvalue

Where a delivery goes when the host has no opinion.

const DEFAULT_READER_SIGNAL_PATH = "/api/reader-signals"

BATCH_CONTENT_TYPEvalue

What a batch is labelled as on the wire: **plain text, which happens to be JSON**.

const BATCH_CONTENT_TYPE = "text/plain;charset=UTF-8"

SendBeacontype

navigator.sendBeacon, narrowed to what this uses. false means it would not take it.

type SendBeacon = (url: string, body: Blob) => boolean;

PostBatchtype

The fallback. Called only when a beacon was unavailable or refused the batch.

type PostBatch = (url: string, body: string) => void;

DeliverOptionstype

type DeliverOptions = {
    /** Where to post. {@link DEFAULT_READER_SIGNAL_PATH} when absent. */
    readonly url?: string;
    /** The browser's, when absent. A test passes its own. */
    readonly beacon?: SendBeacon | null;
    /** `fetch` with `keepalive`, when absent. */
    readonly post?: PostBatch;
};

deliverReaderSignalsfunction

A send for broadcastReaderSignals that posts each batch.

const deliverReaderSignals: (options?: DeliverOptions) => ((batch: ReaderSignalBatch) => void)