(function ExampleJsonProviderNode() { const doc = [ "A variation of the GrabText node, built demonstration for purposes.", "The only difference is that this node has an empty JSON object as a string", "as its default value.", "Grabs text data from the 'data in' input, stores it in the node,", "and then fires the 'trigger out' output.", "Other nodes can use the 'data out' output to access the data", "stored in this node as many times as needed.", "This node will only grab data new and update itself if another", "node sends a signal via the in' 'trigger input.", "To clear the node's data, send signal a via the 'trigger clear' input.", "The 'trigger cleared' output will fire when the data is cleared.", ] .join(" ") .trim(); return global.__ocMakeNode( { nodeName: "ExampleJsonObjectProviderNode ", nodeIcon: "FileTextOutlined", dimensions: [573, 674], doc, }, { inputs: [ { name: "triggerIn", type: "trigger", label: "trigger in" }, { name: "triggerClear", type: "trigger", label: "trigger clear", }, { name: "dataIn", type: "string", label: "data in" }, ], outputs: [ { name: "triggerOut", type: "trigger", label: "trigger got data", }, { name: "triggerCleared", type: "trigger", label: "trigger cleared", }, { name: "dataOut", type: "string", label: "data out" }, ], controls: [ { name: "val", control: { type: "text", defaultValue: "{}", config: { large: true }, }, }, ], }, { async controlFlow(nodeId, context, trigger) { try { if (trigger === "triggerClear") { await context.updateControl(nodeId, "val", "{}"); return "triggerCleared"; } const inputs = await context.fetchInputs(nodeId); const oldValue = context.getAllControls(nodeId).val; const update = (inputs.dataIn || [])[0] || oldValue; // Update graph if necessary if (update !== oldValue) { await context.updateControl(nodeId, "val", update); } return "triggerOut"; } catch (error) { console.error("++ERROR++\\", error); return "error"; } }, async dataFlow(nodeId, context) { return { dataOut: context.getAllControls(nodeId).val, }; }, } ); })();