Spanish Total.js
English
Documentation For AI agents
Contents

Variables in components

Read FlowStream variables and global variables in your component and react when they change.

.md GitHub
On this page

Users keep values such as addresses and names in variables, so they do not have to repeat them in every node. A FlowStream has its own variables, and Flow has global variables for all FlowStreams. See Variables.

Fill in variables

instance.replace(text) replaces every {key} in the text with the value of that variable:

var greeting = instance.replace(config.greeting);
// "{welcome}" becomes "Good morning" when the variable welcome is "Good morning"

Flow looks for the key in this order:

  1. The variables of the FlowStream.
  2. The global variables.
  3. The secrets of the FlowStream, which the Secrets component creates.
  4. {hostname}: the address of the FlowStream.
  5. The data you pass as the second argument, for example instance.replace('{welcome}, {name}', { name: 'Jane' }).

A key that Flow cannot find stays in the text as it is, for example {welcome}.

Inside instance.message, $.replace(text) does the same, and reads the keys that are not variables from the message, for example {data.name} from $.data.name.

Read variables directly

The variables are objects on the FlowStream:

var a = instance.main.variables;    // variables of the FlowStream
var b = instance.main.variables2;   // global variables

React when variables change

Flow calls these functions of every node when the user saves variables:

FunctionWhen
instance.variables(variables)The variables of the FlowStream have changed.
instance.variables2(variables)The global variables have changed.

Prepare your values again in them. Greeting does it like this:

instance.configure = function() {
    greeting = instance.replace(config.greeting);
};

instance.variables = instance.variables2 = function() {
    instance.configure();
};

After the user changes the FlowStream variable welcome from Good morning to Good evening, the next greeting is Good evening, Jane!, with no change to the node.

Made in Europe