Hey there! I'm stuck understanding one simple mechanism. Please enlighten me.
I use a config node and as far as I learned from the docs, I get the content with RED.nodes.getNode. So I do:
Let me describe the situation with the option "bool". In JS, I do:
module.exports = function(RED) {
function configNode(config) {
RED.nodes.createNode(this,config)
this.config = config
}
RED.nodes.registerType("mytemplate-config",configNode);
function workingNode(config) {
RED.nodes.createNode(this,config)
let parms = RED.nodes.getNode(config.config)
...
RED.nodes.registerType("mytemplate",workingNode);
}
...
Which gives me the console output:
configNode {
id: 'f476dc6e65b0a93d',
type: 'mytemplate-config',
z: undefined,
g: undefined,
_closeCallbacks: [],
_inputCallback: null,
_inputCallbacks: null,
name: 'myparms',
wires: [],
_wireCount: 0,
send: [Function: NOOP_SEND],
config: {
id: 'f476dc6e65b0a93d',
type: 'mytemplate-config',
name: 'myparms',
valueType: 'bool',
value: 'true',
_users: [ '01a83f7c216f97b8', 'd2ef1c167664e574' ]
}
}
One parameter field config.value is a typedInput allowing ["bool","num","str"]. I learned that "bool" and "num" are also stored as strings and I have to convert it first. Now in JS I do:
...
if (parms.config.valueType === "bool") {
parms.config.value = parms.config.value === "true"
}
...
Resulting in:
valueType: 'bool',
value: true,
Great. But when calling the node a second time, it fails. If I add a console.log before and after conversion, I see that the second node, before conversion, holds the value from the conversion of the first node.
BEFORE CONVERSION
configNode {
...
config: {
...
valueType: 'bool',
value: 'true',
...
}
}
AFTER CONVERSION
configNode {
...
config: {
...
valueType: 'bool',
value: true,
...
}
}
BEFORE CONVERSION
configNode {
...
config: {
...
valueType: 'bool',
value: true,
...
}
}
AFTER CONVERSION
configNode {
...
config: {
...
valueType: 'bool',
value: false,
...
}
}
Find the complete code here: GitHub - danube/template
Doh... kinda hard to explain, hope you got it. Now may you guide me to the right path please... Regards! Thomas