flowcomponents icon indicating copy to clipboard operation
flowcomponents copied to clipboard

Example boilerplate for flow components.

Open inventclem opened this issue 8 years ago • 5 comments

Hi Peter/Martin,

This is more a question rather than an issue!

Is it possible to put an example boilerplate component code for developers who want to add their own kind of components to Totaljs Flow?

Ideally, I am having trouble understanding how a component "fits together" in terms of inputs, outputs and logic performed by the component.

For instance, if I have a component that needs to take 2 numbers and add them together and send that to an output... How would one construct a simple component that achieves such a feature in terms of Inputs / Logic / Output?

Fantastic Library! Loving the flow components you have built so far! Looking to build a few of my own.

inventclem avatar Jan 22 '18 14:01 inventclem

Hi @inventclem, yes, I want to prepare a Wiki for it https://wiki.totaljs.com/flow/05-creating-components/ but it's uncompleted yet.

in terms of inputs, outputs and logic performed by the component: it's very easy to understand. Imagine some component:

// INPUTS (receiving data):
instance.on('data', function(response) {
    // the component received data to some input
});

instance.on('0', function(response) {
    // the component received data to the INPUT 0
});

instance.on('1', function(response) {
    // the component received data to the INPUT 1
});

instance.on('2', function(response) {
    // the component received data to the INPUT 2
});
// OUTPUTS (send data next)

// Sending data to all outputs
instance.send({ your: 'data' });
instance.send('Peter');

// Sending data to output 0
instance.send(0, { your: 'data' });

// Sending data to output 1
instance.send(1, 'Peter');

// Sending data to output 2
instance.send(2, <buffer ...>);

Together:

instance.on('data', function(response) {
     // We expect number to input
     // Docs: https://github.com/totaljs/flow#message
     // response.data contains the raw VALUE

     // We increase this number
     response.data += 10;

     // Send data next
     // So the next component receives updated number
     instance.send(response);
});

Write me on Total.js messenger for more info. Thank you!

petersirka avatar Jan 22 '18 15:01 petersirka

Hello, I am creating my own component on Dashboard and then send the data to a flow component. Can I use the same guideline https://wiki.totaljs.com/flow/05-creating-components/ for creating Dashboard components? If I have multiple data, how do I select which one to be sent/received? Thank you.

ductran54 avatar Dec 03 '19 14:12 ductran54

Hi @ductran54, some features are same... try it. Our plan is to upgrade Dashboard package and improve functionality.

petersirka avatar Dec 03 '19 14:12 petersirka

Hi Peter, I am wondering if there is a way to hide ... in Dashboard in release.js (basically preventing users from editing dashboard), but keep it for editing when running debug.js mode. Thank you!

ductran54 avatar Dec 04 '19 21:12 ductran54

~Now~ No, but you can modify a bit dashboard or we can modify it within Total.js Support (it's a work for max. 2 hours)

petersirka avatar Dec 04 '19 22:12 petersirka