moderator-toolbox-nxg-for-reddit / framework/lifecycle

framework/lifecycle

Functions

createLifecycle()

createLifecycle(): Lifecycle

Defined in: extension/data/framework/lifecycle.ts:75

Owns side effects created during module initialization.

Example:

const lifecycle = createLifecycle();
lifecycle.on(window, 'resize', onResize);
lifecycle.interval(refresh, 60_000);
return lifecycle.cleanup;

Returns

Lifecycle


throwIfErrors()

throwIfErrors(errors, message): void

Defined in: extension/data/framework/lifecycle.ts:10

Throws a collected errors array: rethrows a single error directly, or wraps multiple errors in an AggregateError with the given message.

Parameters

errors

unknown[]

message

string

Returns

void

Interfaces

Lifecycle

Defined in: extension/data/framework/lifecycle.ts:19

Methods

cleanup()

cleanup(): Promise<void>

Defined in: extension/data/framework/lifecycle.ts:61

Run registered cleanup functions in reverse registration order.

Returns

Promise<void>

delegate()

delegate<E>(parent, type, selector, handler): Cleanup

Defined in: extension/data/framework/lifecycle.ts:48

Attach a delegated event listener and register its matching removal.

Type Parameters
E

E extends Event = Event

Parameters
parent

Element | Document

type

string

selector

string

handler

(target, event) => void

Returns

Cleanup

interval()

interval(handler, ms): Cleanup

Defined in: extension/data/framework/lifecycle.ts:57

Start an interval and register clearInterval.

Parameters
handler

() => void

ms

number

Returns

Cleanup

mount()

mount(cleanup): Cleanup

Defined in: extension/data/framework/lifecycle.ts:21

Register a cleanup function to run when this lifecycle is cleaned up.

Parameters
cleanup

Cleanup

Returns

Cleanup

observe()

observe(target, callback, options): Cleanup

Defined in: extension/data/framework/lifecycle.ts:55

Create a MutationObserver, start observing, and register .disconnect().

Parameters
target

Node

callback

MutationCallback

options

MutationObserverInit

Returns

Cleanup

on()
Call Signature

on<K>(target, type, listener, options?): Cleanup

Defined in: extension/data/framework/lifecycle.ts:23

Add an event listener and register its matching removal.

Type Parameters
K

K extends keyof WindowEventMap

Parameters
target

Window

type

K

listener

(event) => void

options?

boolean | AddEventListenerOptions

Returns

Cleanup

Call Signature

on<K>(target, type, listener, options?): Cleanup

Defined in: extension/data/framework/lifecycle.ts:29

Type Parameters
K

K extends keyof DocumentEventMap

Parameters
target

Document

type

K

listener

(event) => void

options?

boolean | AddEventListenerOptions

Returns

Cleanup

Call Signature

on<K>(target, type, listener, options?): Cleanup

Defined in: extension/data/framework/lifecycle.ts:35

Type Parameters
K

K extends keyof HTMLElementEventMap

Parameters
target

HTMLElement

type

K

listener

(event) => void

options?

boolean | AddEventListenerOptions

Returns

Cleanup

Call Signature

on(target, type, listener, options?): Cleanup

Defined in: extension/data/framework/lifecycle.ts:41

Parameters
target

EventTarget

type

string

listener

EventListenerOrEventListenerObject

options?

boolean | AddEventListenerOptions

Returns

Cleanup

timeout()

timeout(handler, ms): Cleanup

Defined in: extension/data/framework/lifecycle.ts:59

Start a timeout and register clearTimeout.

Parameters
handler

() => void

ms

number

Returns

Cleanup