Skip to content

BrowserStream

Browser DOM event streams.

This module provides typed constructors that turn window.addEventListener and document.addEventListener events into Effect Stream values. Both helpers accept the usual listener options and an optional stream buffer size.

2 exports Added in v4.0.0 Source

Constructors

Creates a Stream from document.addEventListener.

Details

By default, the underlying buffer is unbounded in size. You can customize the buffer size by passing an object as the second argument with the bufferSize field.

Signature

declare function fromEventListenerDocument<K extends keyof DocumentEventMap>(
  type: K,
  options?:
    | boolean
    | {
        readonly bufferSize?: number;
        readonly capture?: boolean;
        readonly once?: boolean;
        readonly passive?: boolean;
      },
): Stream<DocumentEventMap[K], never, never>;

Creates a Stream from window.addEventListener.

Details

By default, the underlying buffer is unbounded in size. You can customize the buffer size by passing an object as the second argument with the bufferSize field.

Signature

declare function fromEventListenerWindow<K extends keyof WindowEventMap>(
  type: K,
  options?:
    | boolean
    | {
        readonly bufferSize?: number;
        readonly capture?: boolean;
        readonly once?: boolean;
        readonly passive?: boolean;
      },
): Stream<WindowEventMap[K], never, never>;