Skip to content

Latest commit

 

History

History
713 lines (434 loc) · 17.9 KB

README.md

File metadata and controls

713 lines (434 loc) · 17.9 KB

futurise

futurise

Table of contents

Type Aliases

Functions

Type Aliases

Listener

Ƭ Listener<E>: (event: E) => void

Type parameters

Name Type
E extends object

Type declaration

▸ (event): void

Parameters
Name Type
event E
Returns

void

Defined in

types.ts:1


ListenerOptions

Ƭ ListenerOptions: Parameters<EventTarget["addEventListener"]>[2]

Defined in

types.ts:3


PromiseStatus

Ƭ PromiseStatus: "idle" | "pending" | "fulfilled" | "rejected"

Status of a promise.

Defined in

types.ts:12


Register

Ƭ Register<L, O>: (listener: L, options?: O) => Unregister

Type parameters

Name
L
O

Type declaration

▸ (listener, options?): Unregister

Parameters
Name Type
listener L
options? O
Returns

Unregister

Defined in

types.ts:7


Unregister

Ƭ Unregister: () => void

Type declaration

▸ (): void

Returns

void

Defined in

types.ts:5

Functions

interval

interval(duration, callback): Unregister

Calls callback at least every duration milliseconds. Returns a function that stops future calls of callback. If duration is falsy, uses requestAnimationFrame if available.

Parameters

Name Type Description
duration number Duration of each interval in milliseconds.
callback () => void Called at the end of each interval.

Returns

Unregister

Function that cancels the interval.

Defined in

tools/interval.ts:19


on

on<K>(target, eventName, listener, options?): Unregister

Listens for event on target, calling listener(event) at each incoming event. The provided options are identical to those provided to addEventListener. Returns a function that removes the listener from the target for the specified event.

Type parameters

Name Type
K extends keyof HTMLElementEventMap

Parameters

Name Type Description
target HTMLElement The target on which to listen for the event.
eventName K -
listener Listener<HTMLElementEventMap[K]> The listener callback.
options? boolean | AddEventListenerOptions Options to pass to the listener.

Returns

Unregister

A function that removes the listener.

Defined in

tools/on.ts:13

on<K>(target, eventName, listener, options?): Unregister

Type parameters

Name Type
K extends keyof DocumentEventMap

Parameters

Name Type
target Document
eventName K
listener Listener<DocumentEventMap[K]>
options? boolean | AddEventListenerOptions

Returns

Unregister

Defined in

tools/on.ts:19

on<K>(target, eventName, listener, options?): Unregister

Type parameters

Name Type
K extends keyof WorkerEventMap

Parameters

Name Type
target Worker
eventName K
listener Listener<WorkerEventMap[K]>
options? boolean | AddEventListenerOptions

Returns

Unregister

Defined in

tools/on.ts:25

on<E>(target, eventName, listener, options?): Unregister

Type parameters

Name Type
E extends object

Parameters

Name Type
target EventTarget
eventName string
listener Listener<E>
options? boolean | AddEventListenerOptions

Returns

Unregister

Defined in

tools/on.ts:31

on<K>(target, eventName): Register<Listener<HTMLElementEventMap[K]>, ListenerOptions>

Returns a function that registers a listener with optional options for a given event on the provided target.

Type parameters

Name Type
K extends keyof HTMLElementEventMap

Parameters

Name Type Description
target HTMLElement The target on which to listen for the event.
eventName K -

Returns

Register<Listener<HTMLElementEventMap[K]>, ListenerOptions>

Function that registers a listener with optional options.

Example

const register = on(element, "click");
// Start listening
const off = register(callback);
// Stop listening
off();

Defined in

tools/on.ts:53

on<K>(target, eventName): Register<Listener<DocumentEventMap[K]>, ListenerOptions>

Type parameters

Name Type
K extends keyof DocumentEventMap

Parameters

Name Type
target Document
eventName K

Returns

Register<Listener<DocumentEventMap[K]>, ListenerOptions>

Defined in

tools/on.ts:57

on<K>(target, eventName): Register<Listener<WorkerEventMap[K]>, ListenerOptions>

Type parameters

Name Type
K extends keyof WorkerEventMap

Parameters

Name Type
target Worker
eventName K

Returns

Register<Listener<WorkerEventMap[K]>, ListenerOptions>

Defined in

tools/on.ts:61

on<E>(target, eventName): Register<Listener<E>, ListenerOptions>

Type parameters

Name Type
E extends object

Parameters

Name Type
target EventTarget
eventName string

Returns

Register<Listener<E>, ListenerOptions>

Defined in

tools/on.ts:65


once

once<K>(target, eventName, listener, options?): Unregister

Listens for event on target, calling listener(event) at the first occuring event. The listener is then unregistered upon the first occurence. The provided options are identical to those provided to addEventListener. Returns a function that removes the listener from the target for the specified event.

Type parameters

Name Type
K extends keyof HTMLElementEventMap

Parameters

Name Type Description
target HTMLElement The target on which to listen for the event.
eventName K -
listener Listener<HTMLElementEventMap[K]> The listener callback.
options? boolean | AddEventListenerOptions Options to pass to the listener.

Returns

Unregister

A function that removes the listener.

Defined in

tools/once.ts:13

once<K>(target, eventName, listener, options?): Unregister

Type parameters

Name Type
K extends keyof DocumentEventMap

Parameters

Name Type
target Document
eventName K
listener Listener<DocumentEventMap[K]>
options? boolean | AddEventListenerOptions

Returns

Unregister

Defined in

tools/once.ts:19

once<K>(target, eventName, listener, options?): Unregister

Type parameters

Name Type
K extends keyof WorkerEventMap

Parameters

Name Type
target Worker
eventName K
listener Listener<WorkerEventMap[K]>
options? boolean | AddEventListenerOptions

Returns

Unregister

Defined in

tools/once.ts:25

once<E>(target, eventName, listener, options?): Unregister

Type parameters

Name Type
E extends object

Parameters

Name Type
target EventTarget
eventName string
listener Listener<E>
options? boolean | AddEventListenerOptions

Returns

Unregister

Defined in

tools/once.ts:31

once<K>(target, eventName): Register<Listener<HTMLElementEventMap[K]>, ListenerOptions>

Returns a function that registers a listener with optional options for a given event on the provided target. The listener is then unregistered upon the first occurence of the event.

Type parameters

Name Type
K extends keyof HTMLElementEventMap

Parameters

Name Type Description
target HTMLElement The target on which to listen for the event.
eventName K -

Returns

Register<Listener<HTMLElementEventMap[K]>, ListenerOptions>

Function that registers a listener with optional options.

Example

const register = on(element, "click");
// Start listening
const off = register(callback);
// Stop listening
off();

Defined in

tools/once.ts:53

once<K>(target, eventName): Register<Listener<DocumentEventMap[K]>, ListenerOptions>

Type parameters

Name Type
K extends keyof DocumentEventMap

Parameters

Name Type
target Document
eventName K

Returns

Register<Listener<DocumentEventMap[K]>, ListenerOptions>

Defined in

tools/once.ts:57

once<K>(target, eventName): Register<Listener<WorkerEventMap[K]>, ListenerOptions>

Type parameters

Name Type
K extends keyof WorkerEventMap

Parameters

Name Type
target Worker
eventName K

Returns

Register<Listener<WorkerEventMap[K]>, ListenerOptions>

Defined in

tools/once.ts:61

once<E>(target, eventName): Register<Listener<E>, ListenerOptions>

Type parameters

Name Type
E extends object

Parameters

Name Type
target EventTarget
eventName string

Returns

Register<Listener<E>, ListenerOptions>

Defined in

tools/once.ts:65


reduceStatusList

reduceStatusList(...statusList): PromiseStatus

Returns a reduced promise status, prioritizing "rejected" over "pending" over "idle" over "fulfilled".

Parameters

Name Type Description
...statusList PromiseStatus[] List of promise statuses.

Returns

PromiseStatus

The reduced promise status.

Defined in

tools/reduceStatusList.ts:9


sleep

sleep(duration, signal?): Promise<unknown>

Returns a promise that resolves after at least duration milliseconds elapsed. If a signal is provided, listens for an abort event to reject the promise with the signal.reason.

Parameters

Name Type Description
duration number Sleep duration in milliseconds.
signal? AbortSignal Optional signal parameter on which the abort event will be listened to.

Returns

Promise<unknown>

Defined in

tools/sleep.ts:13


timeout

timeout(duration, callback): Unregister

Calls callback after at least duration milliseconds. Returns a function that cancels the future call of callback, if not already called.

Parameters

Name Type Description
duration number Timeout duration in milliseconds.
callback () => void Called after the duration elapsed.

Returns

Unregister

Function that cancels the call of callback.

Defined in

tools/timeout.ts:20


until

until<E>(register, signal?, sentinel?): Promise<E>

Listens for an event with the provided register function until it happens or until sentinel(event) returns a truthy value. If a signal is provided, listens to it to cancel the promise.

Type parameters

Name Type
E extends object = Event

Parameters

Name Type Description
register Register<Listener<E>, any> Function that registers a listener for the event to catch.
signal? AbortSignal Optional signal parameter on which the abort event will be listened to.
sentinel? (event: E) => boolean Optional sentinel function that validates an event occurence.

Returns

Promise<E>

A promise that resolves to the event.

Defined in

tools/until.ts:12


untilOnline

untilOnline(signal?): Promise<boolean>

Returns a promise that waits for the browser to be back online. Resolves to true if it it was offline before calling this function, false otherwise. If a signal is provided, listens to it to cancel the promise.

Parameters

Name Type Description
signal? AbortSignal Optional signal parameter on which the abort event will be listened to.

Returns

Promise<boolean>

true if it it was offline before calling this function, false otherwise.

Defined in

tools/untilOnline.ts:14