Skip to content

Variables

Julian Waller edited this page Oct 25, 2022 · 2 revisions

Modules are able to expose values to the user, which they can use as part of the button text, or as input to some actions.

This section explains how to define variables and change update their values.

Your module can define the list of variables it exposes by making a call to this.setVariableDefinitions({ ...some variables here... }). You will need to do this as part of your init() method, but can also call it at any other time if you wish to update the list of variables exposed.

Note: Please try not to do it too often, as updating the list has a cost. If you are calling it multiple times in a short span of time, consider if it would be possible to batch the calls so it is only done once.

The boilerplate has a file variables.js which is where your variables should be defined. It is not required to use this structure, but it keeps it more readable than having it all in one file.

All the variable definitions are passed in one javascript array, such as:

;[
	{ variableId: 'variable1', name: 'My first variable' },
	{ variableId: 'variable2', name: 'My second variable' },
	{ variableId: 'variable3', name: 'Another variable' },
]

Note: variableId must only use letters [a-zA-Z], numbers, underscore, hyphen.

At any point in your module you can call this.setVariableValues({ ... new values ... }). You can specify as many or few variables as you wish in this call. Only the ones you specify will be updated.

This may look like:

this.setVariableValues({
    'variable1': 'new value'
    'variable2': 99,
    'old_variable': undefined // This unsets a value
})

Note: Please try to batch variable updates whenever possible, as updating the values has a cost. If you are calling it multiple times in a short span of time, consider if it would be possible to batch the calls so it is only done once.

The function on callback is what gets executed when the action is executed. It used to be possible to define this elsewhere, but that is no longer the case. You can see a description of the action object passed into the callback in the documentation. Make sure to not use any of the deprecated properties, they will be removed without warning!

There are more properties available, which are described in full in the documentation

The options property of the action definition is an array of input types, as defined here

Clone this wiki locally