abstract
Context
Softcoded application context
Contexts have parents and children, they represent the lifecycle of bricks. They contain callbacks executed at specific time of the brick lifespan.
Each time a brick is updated with new inputs, Context.clear is called, executing all callbacks registered with Context.onClear.
When a brick is destroyed, Context.destroy is called, executing all callbacks registered with Context.onClear and Context.onDestroy
Constructors
new Context()
new Context(): Context
Returns
Context
Methods
clear()
clear(): void
Clear the current context: detach and destroys all children context. The context can be reused.
Returns
void
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
isDestroyed()
isDestroyed(): boolean
Whether the context is destroyed.
Returns
boolean
offClear()
offClear(id): void
Remove a previously registered callback with Context.onClear method using its id.
Parameters
Parameter | Type | Description |
---|---|---|
id | string | the id of the callback to unregister |
Returns
void
offDestroy()
offDestroy(callbackId): boolean
Remove a previously registered callback with Context.onDestroy method using its id.
Parameters
Parameter | Type | Description |
---|---|---|
callbackId | string | the id of the callback to unregister |
Returns
boolean
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
Parameter | Type | Description |
---|---|---|
callback | () => void | the callback function |
Returns
string
the callback id
onDestroy()
onDestroy(callback): string
Register a callback to execute when the context is destroyed. Return the callback id.
Parameters
Parameter | Type | Description |
---|---|---|
callback | () => void | the callback function |
Returns
string
the callback id