Variables in components
Read FlowStream variables and global variables in your component and react when they change.
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:
- The variables of the FlowStream.
- The global variables.
- The secrets of the FlowStream, which the Secrets component creates.
{hostname}: the address of the FlowStream.- 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 variablesReact when variables change
Flow calls these functions of every node when the user saves variables:
| Function | When |
|---|---|
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.