Skip to main content

IVariable interface

📖 Description​

Describes the interface that holds a variable.

📃 Type declaration​

interface IVariable {
  id: string;Readonly
  string: string;Readonly
  hasValue: boolean;Readonly
  value?: any;ReadonlyOptional
  reference?: string;ReadonlyOptional
  content: {
    value: string;
    type: "string" | "text" | "markdown";
    separator: string;
  }[];Readonly
  slot?: Slot;ReadonlyOptional
  subscribe: (fnChange: (variable: IVariable) => void, context?: {}) => void;Function
  unsubscribe: (context: {}) => void;Function
}
🖱ī¸ Hover with the mouse over a property name for a tooltip with the description of that property. Click it for more information.

🗃ī¸ Properties​


🏷ī¸ content​

Contains the content for the variable. This array has at least one item but can contain more if the variable has multiple values in different contexts.

Type​

{
/*
* Contains the type of value. It can be one of the following values:
* - `string`: `value` contains the variable value as a string;
* - `text`: `value` contains text with basic markdown support for referencing variables;
* - `markdown`: `value` contains markdown content with support for basic formatting, hyperlinks and referencing variables.
*/
type: "string" | "text" | "markdown";

/* Contains the value defined by the `type` property. */
value: string;

/* Contains the character to use as separator when concatenating multiple value content parts. */
separator: string;
}[]

🏷ī¸ hasValue​

Retrieves if a valid value is present.

Type​

boolean


🏷ī¸ id​

Contains the identifier of the variable.

Type​

string


🏷ī¸ reference​

Retrieves the additional reference that can be set. This reference is used by some blocks to store an additional identifier related to the value. For example, when a value from a dropdown block is set, the reference is used to store the identifier of the selected item.

Type​

string


🏷ī¸ slot​

Reference to the slot that defines the data value.

Type​

Slot


🏷ī¸ string​

Contains the value as a string.

Type​

string


🏷ī¸ value​

Retrieves the value (can be undefined when there is no value set).

Type​

any

â–ļī¸ Functions​


🔧 subscribe​

Subscribes a listener to the variable. This listener function is invoked when the variable changes. It is also possible to supply a context. This context is used when you want to unsubscribe all the listener functions attached to the supplied context.

Signature​

(onChange: (variable: IVariable) => void, context?: {}) => void

Parameters​

NameTypeOptionalDescription
onChange(variable: IVariable) => voidNoSpecifies the function that is called when a change is detected.

Example​

const variable: IVariable;
const context = {};

// Subscribes a listener function and attaches the function to the supplied context
variable.subscribe((v) => console.log(`New value: ${v.string}`), context);

// And, when you want to unsubscribe all listeners attached to the context do:
variable.unsubscribe(context);

🔧 unsubscribe​

Unsubscribe the listener functions attached to a context.

Signature​

(context: {}) => void

Parameters​

NameTypeOptionalDescription
context{}NoSpecifies the context to unsubscribe.