Spanish Total.js
English
Documentation For AI agents
Contents

Your first component

Create a component in the designer, use it in a FlowStream and install it from a file.

.md GitHub
On this page

This page builds Uppercase, a component that turns the text it receives into capital letters, and runs it between a Trigger and a Print node.

Create the component

  1. Open a FlowStream in the designer.
  2. Select Add (plus), then Create new component.
  3. The Source code window opens with a template of a component.

The Source code window with the template of a new component

  1. Replace the whole template with this code:
<script total>

    exports.id = 'uppercase';
    exports.name = 'Uppercase';
    exports.icon = 'ti ti-font';
    exports.author = 'Jane Doe';
    exports.version = '1';
    exports.group = 'Demo';
    exports.config = {};
    exports.inputs = [{ id: 'input', name: 'Input' }];
    exports.outputs = [{ id: 'output', name: 'Output' }];

    exports.make = function(instance, config) {

        instance.message = function($) {
            $.send('output', String($.data).toUpperCase());
        };

    };

</script>

<readme>
Converts the incoming data to uppercase text.
</readme>

<body>
    <header>
        <i class="$ICON"></i>$NAME
    </header>
</body>
  1. Select APPLY.

Uppercase appears in the list of components on the left, in the Demo group.

Use it

  1. Download Trigger and Print if the FlowStream does not have them. See Download components.
  2. Drag Trigger, Uppercase and Print onto the canvas and connect them in this order. See Add and connect nodes.
  3. Configure the Trigger node: clear Random data and type hello flow in Data.
  4. Select APPLY in the toolbar to start the design.
  5. Select Run on the Trigger node.

Print shows HELLO FLOW.

Trigger, Uppercase and Print connected, with HELLO FLOW in the Print node

What the code does

  • exports.id, exports.name, exports.icon and the other properties describe the component.
  • exports.inputs and exports.outputs create the connection points of the node.
  • Flow calls exports.make once for each node. It receives the instance of the node and its config.
  • Flow calls instance.message for every message that arrives. $ is the message, $.data its data.
  • $.send('output', ...) sends new data to the output with the id output.

Change the component

  1. Right-click the Uppercase node and select Edit source code.
  2. Change the code and select APPLY.

Flow replaces the component in this FlowStream and restarts its nodes with the new code.

Install it from a file

Save the code as uppercase.html on a web server. In another FlowStream, select Add, then Link component, and enter the address of the file. See Install a component from a URL.

To offer many components to your team, publish them in your own catalogue.

Made in Europe