1/**
2 * Browser DOM event streams.
3 *
4 * This module provides typed constructors that turn `window.addEventListener`
5 * and `document.addEventListener` events into Effect `Stream` values. Both
6 * helpers accept the usual listener options and an optional stream buffer size.
7 *
8 * @since 4.0.0
9 */
10
11import * as Stream from "effect/Stream"
12
13/**
14 * Creates a `Stream` from `window.addEventListener`.
15 *
16 * **Details**
17 *
18 * By default, the underlying buffer is unbounded in size. You can customize the
19 * buffer size by passing an object as the second argument with the `bufferSize`
20 * field.
21 *
22 * @category constructors
23 * @since 4.0.0
24 */
25export const fromEventListenerWindow = <K extends keyof WindowEventMap>(
26 type: K,
27 options?: boolean | {
28 readonly capture?: boolean
29 readonly passive?: boolean
30 readonly once?: boolean
31 readonly bufferSize?: number | undefined
32 } | undefined
33): Stream.Stream<WindowEventMap[K], never, never> => Stream.fromEventListener<WindowEventMap[K]>(window, type, options)
34
35/**
36 * Creates a `Stream` from `document.addEventListener`.
37 *
38 * **Details**
39 *
40 * By default, the underlying buffer is unbounded in size. You can customize the
41 * buffer size by passing an object as the second argument with the `bufferSize`
42 * field.
43 *
44 * @category constructors
45 * @since 4.0.0
46 */
47export const fromEventListenerDocument = <K extends keyof DocumentEventMap>(
48 type: K,
49 options?: boolean | {
50 readonly capture?: boolean
51 readonly passive?: boolean
52 readonly once?: boolean
53 readonly bufferSize?: number | undefined
54 } | undefined
55): Stream.Stream<DocumentEventMap[K], never, never> =>
56 Stream.fromEventListener<DocumentEventMap[K]>(document, type, options)