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
Parameter | Type | Description |
---|---|---|
debugName? | string | a 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
Parameter | Type | Description |
---|---|---|
key | string | Property <T > | the property or key string |
global? | boolean | whether 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
Parameter | Type | Description |
---|---|---|
selector | { modelTag : InstanceOrTag ; } | the context selector |
selector.modelTag | InstanceOrTag | tag 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
Parameter | Type | Description |
---|---|---|
id | string | the 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
Parameter | Type | Description |
---|---|---|
key | string | Property <T > | the property or key string |
global? | boolean | whether 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
Parameter | Type | Description |
---|---|---|
key | string | Property <T > | the property or key string |
waitForValue? | boolean | whether the observable should wait for a first value to get a value. (Default = true) |
global? | boolean | whether 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
Parameter | Type | Description |
---|---|---|
id | string | the context id, which corresponds to the tag of the brick to be retrieved. |
callback | (context ) => void | the 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
Parameter | Type | Description |
---|---|---|
global? | boolean | if 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
Parameter | Type | Description |
---|---|---|
global? | boolean | if 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
Parameter | Type | Description |
---|---|---|
key | string | 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
Parameter | Type | Description |
---|---|---|
key | string | Property <T > | the key used to set the values coming from the observable |
observable | Observable <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
Parameter | Type | Description |
---|---|---|
key | | string | Property <T > | Brick | the 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
Parameter | Type | Description |
---|---|---|
key | string | Property <T > | the property or key string |
value | T | the new value to set |
Returns
this
this
setParentElement()
setParentElement(parent): this;
Set the parent element for visual brick to be rendered.
Parameters
Parameter | Type | Description |
---|---|---|
parent | Element | the 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
Parameter | Type | Description |
---|---|---|
error | string | ErrorFlow | Error | the 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
Parameter | Type | Description |
---|---|---|
key | string | 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
Parameter | Type | Description |
---|---|---|
key | string | Property <T > | the property |
global? | boolean | whether the method checks parent contexts (Default = false) |
Returns
Promise
<T
>
a promise of the next value of property