Skip to main content
Version: Next

BrickContext

Extends

  • unknown

Constructors

Constructor

new BrickContext(): BrickContext;

Returns

BrickContext

Inherited from

Context.constructor

Methods

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


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


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


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

(): void;
Returns

void


printHierarchy()

printHierarchy(): void;

Print the hierarchy around this context. Access a nested object with the names of context arranged in parent and children attributes.

Returns

void


printUserDefinedValues()

printUserDefinedValues(global?): void;

Prints the user-defined values from this context. (incl. parents if global is true) A user-defined value is a value set in a context using the BrickContext.set method or Set in Context brick. These values have a string keys and are not tied to any property/input/outputs.

Parameters

ParameterTypeDescription
global?booleanif the user defined values from parent(s) are included or not. (Default = false)

Returns

void


printValues()

printValues(global?): void;

Prints all values stored in this context: I/O, properties and user-defined properties. See BrickContext.printUserDefinedValues for user-defined properties definition.

Parameters

ParameterTypeDescription
global?booleanif values from parent(s) are included or not. (Default = false)

Returns

void


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
key| string | 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