Array
Description
This object is being used to provide a standardized way to address all functions of an 'Array'.
The name of the object can be used to uniquely identify this array within the app. When another 'Array' object is dragged onto the canvas and has been named the exact same way, they will share their information which each other. For info on this behavior read this: https://quantumintegrate.atlassian.net/wiki/spaces/QOR/pages/351830091.
App Builder Object
Source Code
function execute() {
const identifierArr = `${nodeName}-array`;
const identifierIndex = `${nodeName}-index`;
// Setup array
if (globalContext[identifierArr] === undefined) {
globalContext[identifierArr] = [];
}
if (globalContext[identifierIndex] === undefined) {
globalContext[identifierIndex] = inPorts[1].value || -1;
}
switch (trigger) {
case 0:
// Initialize Array
globalContext[identifierArr] = [];
globalContext[identifierIndex] = -1;
break;
case 1:
// Set Index
globalContext[identifierIndex] = inPorts[1].value;
editInPort(1, {});
break;
case 3:
// Read
return [globalContext[identifierArr][globalContext[identifierIndex]], globalContext[identifierArr].length];
case 4:
// Write
if (globalContext[identifierIndex] === -1) {
const index = globalContext[identifierArr].length === 0 ? 0 : globalContext[identifierArr].length;
globalContext[identifierArr][index] = inPorts[2].value;
} else {
globalContext[identifierArr][globalContext[identifierIndex]] = inPorts[2].value;
}
break;
default: break;
}
return [];
}
Example
= empty / no message sent to
Actions | Initialize | Index | Value (In Port) | Read | Write | Value (Out Port) | Length |
---|---|---|---|---|---|---|---|
1. Initialize | Trigger | ||||||
2. Write | 1 | “Test“ | Trigger | ||||
3. Read | 1 | Trigger | “Test“ | 2 |
In Ports
Position | Name | Message Type | Description |
---|---|---|---|
1 | Initialize | Trigger | This port is being used to initialize the 'Array' Object. |
2 | Index | Number | This port is being used to set the index for the read or write port action. |
3 | Value | String | This port is being used to receive a message containing the value, which is supposed to be written to the 'Array'. |
4 | Read | Trigger | This port is being used to trigger the read functionality and look for a value at the defined index of the 'Array'. |
5 | Write | Trigger | This port is being used to trigger the write of the value specified at the index into the 'Array'. |
Out Ports
Position | Name | Message Type | Description |
---|---|---|---|
1 | Value | String | This port is being used to send out the message including the value read out of the 'Array' defined by the received index message. |
2 | Length | Number | This port is being used to send out the length of the current 'Array'. |
Properties
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. |
Duplicate code into custom Code Object |