Custom Snippet

Description

This object is being used to create your own code snippets. You can add multiple In and Out ports as well as modify the source code. If you don’t want to start from scratch you can always open the source code of an existing snippet and click the blue icon in the top right hand corner of the code view 'Copy into custom code snippet'.


App Builder Object

 


Source Code

/* You've chosen to write your own snippets. Props to you. This snippet can run any Javascript ES6 code. Make sure to always have a execute function (can be async). The execute function will be the entrypoint of the custom snippet. The following variables are passed in to this custom snippet: context - Object that can be used for storing values. Unique to object and persistent for app runtime. globalContext - Same as context but is unique to application, so every object within an app references the same globalContext. inPorts - Array containing the message objects of the Inputs, which contain value and type (immutable). Input port 1 corresponds to inPorts[0]. nodeName - Name of the current object (immutable). trigger - Index of inPort that triggered execution of snippet (immutable). triggerCallback - Boolean that specifies if outport messages will be transfered to connected objects/ports. TRIGGERS - Object containing system triggers (immutable): - SYSTEM_ASYNC: Object got triggered by asynchronous event (e.g. async sleep). - SYSTEM_SYNC: Object got triggered by a synchronous event (e.g. sync sleep). - SYSTEM_OUT_DONE: Object got triggered as a result finished execution of all links connected to object, when sync method has been used (sendSync and sleepSync). The following additional methods are available: cancelSleep - No parameters.Cancels active sleep. debug - Accepts as many parameters and types as you want and displays them in the app debug dialog. sleep - Accepts milliseconds as a parameters and asynchronously sleeps for specified duration triggering object with trigger SYSTEM_ASYNC when duration reached. Following objects and links will be executed. sleepSync - Accepts milliseconds as a parameters and asynchronously sleeps for specified duration triggering object with trigger SYSTEM_SYNC when duration reached. Following objects will wait until unblock is called or object returns array of values. sendSync - Accepts an array of values the same way you would return to trigger the links, but also sets a sync flag leading to the object to be called again with trigger SYSTEM_OUT_DONE once every linked object and transidients finished executing. Furthermore while sync flag is set no other branches before object will be executed until unblock is called or return is called. unblock - Method without parameters. Will remove the sync flag set by sendSync and notify objects that are connected to in-ports of object of finished execution. editInPort - Accepts index of inPort and value. Edits the value in the specified in-port index To send values to the out ports return an array (sendSync is only for very specific usecases) from the execute function. Similar to the inPorts, array position 0 represents output port 1. Example Snippet: ┌──────────────────────────┐ │ Multiplication │ ├──────────────────────────┤ │ □ Trigger Product □ | | □ Factor 1 | | □ Factor 2 | ├──────────────────────────┤ │ Custom Snippet │ └──────────────────────────┘ Set Trigger to port type "Trigger" and the rest to "Number". Make sure to disable trigger on every in port except Trigger. Description: Factor 1 and 2 will be filled from other Nodes and once they are the Multiplication Snippet is triggered using the trigger port. Snippet Code: function execute() { switch (trigger) { case 0: { const product = inPorts[1].value * inPorts[2].value; return [product]; } default: break; } } */ function execute() { debug('Hello World!'); }

In Ports

Defined by you


Out Ports

Defined by you


Properties

Name

Description

Name

Description

Object Name

The name of the object on the canvas.

Show Code View

The switch to turn on code view for the Code Object.