-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1023 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
module.exports = (NODE) => {
const inputsIn = NODE.getInputByName('inputs');
const variablesIn = NODE.getInputByName('variables');
const triggerOut = NODE.getOutputByName('trigger');
const triggerIn = NODE.getInputByName('trigger');
triggerIn.on('trigger', async (conn, state) => {
const inputs = await inputsIn.getValues(state);
const variables = await variablesIn.getValues(state);
let values;
const fn = eval(`(function(inputs, variables, trigger, state){${NODE.data.function}})`);
fn(
inputs,
variables.reduce((acc, cur) => {
acc[cur.name] = cur.values; return acc;
}, {}),
() => {
state.set(NODE, {
values
});
triggerOut.trigger(state);
}
);
});
const valuesOut = NODE.getOutputByName('values');
valuesOut.on('trigger', async (conn, state) => {
const thisState = state.get(NODE);
if (!thisState || !thisState.values) {
return;
}
return thisState.values;
});
};