Skip to main content

Scope

Defined in: js-api/src/u2core/scope.ts:5

Owner of effects and cleanups. Everything registered on a scope is released by a single dispose() call; the live-scope count feeds leak detection.

Constructors​

Constructor​

new Scope(): Scope

Defined in: js-api/src/u2core/scope.ts:11

Returns​

Scope

Accessors​

isDisposed​

Get Signature​

get isDisposed(): boolean

Defined in: js-api/src/u2core/scope.ts:35

Returns​

boolean


ambient​

Get Signature​

get static ambient(): Scope | undefined

Defined in: js-api/src/u2core/scope.ts:22

The scope that owns whatever is being built right now, if any. Element factories bind signals to it; components created under it are disposed with it.

Returns​

Scope | undefined


liveCount​

Get Signature​

get static liveCount(): number

Defined in: js-api/src/u2core/scope.ts:16

Number of scopes created and not yet disposed — the leak detector's ground truth.

Returns​

number

Methods​

disown()​

disown(dispose): this

Defined in: js-api/src/u2core/scope.ts:56

Drops a cleanup registered by own — for things that come and go many times over the owner's life (an overlay reopened on every click) and would otherwise leave a dead closure behind on every round.

Parameters​

ParameterType
dispose() => void

Returns​

this


dispose()​

dispose(): void

Defined in: js-api/src/u2core/scope.ts:63

Returns​

void


effect()​

effect(fn): this

Defined in: js-api/src/u2core/scope.ts:40

Runs fn now and on every change of the signals it reads. Disposed with the scope.

Parameters​

ParameterType
fn() => void

Returns​

this


own()​

own(dispose): this

Defined in: js-api/src/u2core/scope.ts:45

Registers a cleanup to run on dispose. Runs immediately if already disposed.

Parameters​

ParameterType
dispose() => void

Returns​

this


runWith()​

static runWith<T>(scope, fn): T

Defined in: js-api/src/u2core/scope.ts:26

Type Parameters​

Type Parameter
T

Parameters​

ParameterType
scopeScope
fn() => T

Returns​

T