Skip to main content
Version: 2.13

BrickContext

Extends​

  • Context

Constructors​

new BrickContext()​

new BrickContext(): BrickContext

Returns​

BrickContext

Inherited from​

Context.constructor

Methods​

clear()​

clear(): void

Clear the current context: detach and destroys all children context. The context can be reused.

Returns​

void

Inherited from​

Context.clear

createChild()​

createChild(debugName?): BrickContext

Create and return a new context, child of the current one. Mainly used to run other bricks within the current one (e.g.: the iterator of the brick For Each).

Parameters​

ParameterTypeDescription
debugName?stringa name to give to the context for debugging purpose.

Returns​

BrickContext


destroy()​

destroy(): void

Destroy the current context. It destroys all children context attached to this one and clear their values. The context cannot be reused after calling this function.

Returns​

void

Inherited from​

Context.destroy

get()​

get<T>(key, global?): T

Return the current value of the specified property. If there is currently no value, return null.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T>the property or key string
global?booleanwhether the method checks parent contexts (Default = false)

Returns​

T

the current value


getClosest()​

getClosest(selector): BrickContext

Return the closest parent of a given type If no context of the specified type is found from the hierarchy, returns the root context.

Parameters​

ParameterTypeDescription
selector{ modelTag: InstanceOrTag; }the context selector
selector.modelTagInstanceOrTagtag of the "type" of context you want to find in the parent tree

Returns​

BrickContext


getOtherContext()​

getOtherContext(id): BrickContext

Return the context with the specified id if accessible (in the hierarchy) from this context. Otherwise, return null.

Parameters​

ParameterTypeDescription
idstringthe context id we want to retrieve

Returns​

BrickContext


getParent()​

getParent(): BrickContext

Return the parent context if it exists.

Returns​

BrickContext


has()​

has<T>(key, global?): boolean

Returns a boolean indicating whether a property has a value or not.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T>the property or key string
global?booleanwhether the method checks parent contexts (Default = false)

Returns​

boolean

whether property has a value or not


isDestroyed()​

isDestroyed(): boolean

Whether the context is destroyed.

Returns​

boolean

Inherited from​

Context.isDestroyed

observe()​

observe<T>(
key,
waitForValue?,
global?): Observable<T>

Return an observable to subscribe to value updates of the specified property. If waitForValue is set to FALSE (TRUE by default), the first value received by the observable is null if there is no value at subscription time. If global is set to TRUE (FALSE by default), it observes values coming from other contexts accessible from the current one.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T>the property or key string
waitForValue?booleanwhether the observable should wait for a first value to get a value. (Default = true)
global?booleanwhether to listen to a value coming from other contexts. (Default = false)

Returns​

Observable<T>

the observable


offClear()​

offClear(id): void

Remove a previously registered callback with Context.onClear method using its id.

Parameters​

ParameterTypeDescription
idstringthe id of the callback to unregister

Returns​

void

Inherited from​

Context.offClear

offDestroy()​

offDestroy(callbackId): boolean

Remove a previously registered callback with Context.onDestroy method using its id.

Parameters​

ParameterTypeDescription
callbackIdstringthe id of the callback to unregister

Returns​

boolean

Inherited from​

Context.offDestroy

onClear()​

onClear(callback): string

Register a callback to execute every time the context is cleared. This happens every time the brick is refreshed with new inputs and during the brick destruction. Return the callback id.

Parameters​

ParameterTypeDescription
callback() => voidthe callback function

Returns​

string

the callback id

Inherited from​

Context.onClear

onContext()​

onContext(id, callback): () => void

Listen to the creation of the context with the specified id. Executes the callback when that context becomes accessible by this current context. Return a function to unregister the listener.

Parameters​

ParameterTypeDescription
idstringthe context id, which corresponds to the tag of the brick to be retrieved.
callback(context) => voidthe function to execute when the specified brick context is available

Returns​

Function

Returns​

void


onDestroy()​

onDestroy(callback): string

Register a callback to execute when the context is destroyed. Return the callback id.

Parameters​

ParameterTypeDescription
callback() => voidthe callback function

Returns​

string

the callback id

Inherited from​

Context.onDestroy

remove()​

remove<T>(key): boolean

Clear the value of the specified property and propagate that event.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T>the property or key string

Returns​

boolean


repeat()​

repeat<T>(key, observable): this

Subscribe to the specified observable and set its values to the context with the provided key.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T>the key used to set the values coming from the observable
observableObservable<T>the observable providing values

Returns​

this

this context


runner()​

runner<T>(key): BrickContext

Run a runnable property and returns its context.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T> | Brickthe runnable property or the runnable itself

Returns​

BrickContext

the child context or null if the runner was not found


set()​

set<T>(key, value): this

Set the specified property value and propagate the update to anyone observing it.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T>the property or key string
valueTthe new value to set

Returns​

this

this


setParentElement()​

setParentElement(parent): this

Set the parent element for visual brick to be rendered.

Parameters​

ParameterTypeDescription
parentElementthe parent container

Returns​

this

this


throw()​

throw(error): this

Throw the specified error to this context. The error will be propagated until it finds an error handler.

Parameters​

ParameterTypeDescription
errorstring | ErrorFlow | Errorthe error to throw and propagate in the contexts hierarchy

Returns​

this

this context


trigger()​

trigger<T>(key): this

Trigger the specified event and propagate the update to anyone observing it.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T>the event or key event

Returns​

this

this


waitFor()​

waitFor<T>(key, global?): Promise<T>

Wait for the property to get a new value, wrapped in a promise. The promise is rejected if no value is set to the specified property before the destruction of this BrickContext.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
keystring | Property<T>the property
global?booleanwhether the method checks parent contexts (Default = false)

Returns​

Promise<T>

a promise of the next value of property