Closed cymplecy closed 10 months ago
Although, I'm beginning to wonder if context properties can be deleted?
I'm a bit confused at the moment
Ok let's make this more clear then...
I quickly made this flow:
[{"id":"69ee3af8e4d3d034","type":"inject","z":"c53e793dd2f3be09","name":"Create vars","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"create","payloadType":"str","x":1010,"y":620,"wires":[["93eed59ecd84aac8"]]},{"id":"93eed59ecd84aac8","type":"Blockly","z":"c53e793dd2f3be09","func":"if ((msg['payload']) == 'create') {\n flow.set('some_property', 'some_value');\n global.set('some_property', 'some_value');\n context.set('some_property', 'some_value');\n} else {\n flow.set('some_property');\n global.set('some_property');\n context.set('some_property');\n}\n","workspaceXml":"<xml xmlns=\"https://developers.google.com/blockly/xml\">\n <block type=\"controls_if\" id=\"=1A/4pa?`Q=-z!2rewBU\" x=\"-1238\" y=\"-1387\">\n <mutation else=\"1\"></mutation>\n <value name=\"IF0\">\n <block type=\"logic_compare\" id=\"`hT.^O#2TNCy!5C8U[6u\">\n <field name=\"OP\">EQ</field>\n <value name=\"A\">\n <block type=\"node_object_get\" id=\"%1:nRx!E*GYvd;@ZVtIm\">\n <mutation xmlns=\"http://www.w3.org/1999/xhtml\" action=\"GET\"></mutation>\n <field name=\"action\">GET</field>\n <value name=\"object\">\n <shadow type=\"node_msg\" id=\"}K3%@~kJ4b4hY5xg3148\"></shadow>\n </value>\n <value name=\"field_name\">\n <shadow type=\"text\" id=\"O.,]cx~RE^eq:m)n%3-h\">\n <field name=\"TEXT\">payload</field>\n </shadow>\n </value>\n </block>\n </value>\n <value name=\"B\">\n <block type=\"text\" id=\"8Gqv]bKy9HNBvlJr1gJf\">\n <field name=\"TEXT\">create</field>\n </block>\n </value>\n </block>\n </value>\n <statement name=\"DO0\">\n <block type=\"node_object_set\" id=\"LmG~}91@HS/yc`]{E=oY\">\n <value name=\"object_field\">\n <shadow type=\"node_msg\" id=\"DYjKc~xI/x(^8G;bFL|r\"></shadow>\n <block type=\"node_flow_memory\" id=\"aoeB~ISiv,[H4sqfzz6E\"></block>\n </value>\n <value name=\"field_name\">\n <shadow type=\"text\" id=\",y,MOaASf)Mu,=9t0,h]\">\n <field name=\"TEXT\">some_property</field>\n </shadow>\n </value>\n <value name=\"value_field\">\n <shadow type=\"text\" id=\"Rf_g^@5l#aX*%[nB(L3t\">\n <field name=\"TEXT\">some_value</field>\n </shadow>\n </value>\n <next>\n <block type=\"node_object_set\" id=\"E)3;yLK@GL|B3Jy)[blW\">\n <value name=\"object_field\">\n <shadow type=\"node_msg\" id=\"DYjKc~xI/x(^8G;bFL|r\"></shadow>\n <block type=\"node_global_memory\" id=\"vS1OtSK9A=(tdA6}z7_5\"></block>\n </value>\n <value name=\"field_name\">\n <shadow type=\"text\" id=\"]I$hF*~/enKAVkdF(rSe\">\n <field name=\"TEXT\">some_property</field>\n </shadow>\n </value>\n <value name=\"value_field\">\n <shadow type=\"text\" id=\"Qnc_aSwFJUJJ~Au./_s5\">\n <field name=\"TEXT\">some_value</field>\n </shadow>\n </value>\n <next>\n <block type=\"node_object_set\" id=\"hQ?qXvt8ytq#XQ/+K(q-\">\n <value name=\"object_field\">\n <shadow type=\"node_msg\" id=\"S)vCplMPViaI(^nycx34\"></shadow>\n <block type=\"node_context_memory\" id=\"A-ma~3+h*Vil]/NavuV@\"></block>\n </value>\n <value name=\"field_name\">\n <shadow type=\"text\" id=\"lC9H,?wGFz*uG=?:z0as\">\n <field name=\"TEXT\">some_property</field>\n </shadow>\n </value>\n <value name=\"value_field\">\n <shadow type=\"text\" id=\"JT#UB8mm67G.ii|ts~%9\">\n <field name=\"TEXT\">some_value</field>\n </shadow>\n </value>\n </block>\n </next>\n </block>\n </next>\n </block>\n </statement>\n <statement name=\"ELSE\">\n <block type=\"node_object_get\" id=\"YDJq@6sDRV7q2hAte_D^\">\n <mutation xmlns=\"http://www.w3.org/1999/xhtml\" action=\"REMOVE\"></mutation>\n <field name=\"action\">REMOVE</field>\n <value name=\"object\">\n <shadow type=\"node_msg\" id=\"QY8.ink~!ff_XNZCbW3;\"></shadow>\n <block type=\"node_flow_memory\" id=\"2S-,Q3HuY^dUG$,+^-SW\"></block>\n </value>\n <value name=\"field_name\">\n <shadow type=\"text\" id=\"NjfG)f]DZ1C^Ww`d(60v\">\n <field name=\"TEXT\">some_property</field>\n </shadow>\n </value>\n <next>\n <block type=\"node_object_get\" id=\",%y[iw6oQpg$P$B,evo(\">\n <mutation xmlns=\"http://www.w3.org/1999/xhtml\" action=\"REMOVE\"></mutation>\n <field name=\"action\">REMOVE</field>\n <value name=\"object\">\n <shadow type=\"node_msg\" id=\"QY8.ink~!ff_XNZCbW3;\"></shadow>\n <block type=\"node_global_memory\" id=\"}gba)Sxcnj*@HWQh(~3H\"></block>\n </value>\n <value name=\"field_name\">\n <shadow type=\"text\" id=\"k{.,FpJrpafB2?fOd7$I\">\n <field name=\"TEXT\">some_property</field>\n </shadow>\n </value>\n <next>\n <block type=\"node_object_get\" id=\"xy)QUf4[yGr@V^f3-q$J\">\n <mutation xmlns=\"http://www.w3.org/1999/xhtml\" action=\"REMOVE\"></mutation>\n <field name=\"action\">REMOVE</field>\n <value name=\"object\">\n <shadow type=\"node_msg\" id=\"ma$Z]8L{+b_sB$uiLK6b\"></shadow>\n <block type=\"node_context_memory\" id=\"cT3beF.VU7:`6|(r4xm,\"></block>\n </value>\n <value name=\"field_name\">\n <shadow type=\"text\" id=\"-)r5ruUkZ0dmP=.JRmX3\">\n <field name=\"TEXT\">some_property</field>\n </shadow>\n </value>\n </block>\n </next>\n </block>\n </next>\n </block>\n </statement>\n </block>\n</xml>","outputs":1,"timeout":"0","blocklyConfig":"46e073e1.66e10c","backpackContents":[],"noerr":0,"name":"","x":1180,"y":620,"wires":[[]]},{"id":"00f4455d3eb4356d","type":"inject","z":"c53e793dd2f3be09","name":"Delete vars","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"delete","payloadType":"str","x":1010,"y":680,"wires":[["93eed59ecd84aac8"]]},{"id":"46e073e1.66e10c","type":"blockly-config","language":"en","showTrashcan":true,"allowComments":true,"showZoomControl":true,"showMiniMap":true,"enableBackPack":true,"backpackContents":["{\"type\":\"object_create\",\"inline\":true,\"extraState\":\"<mutation xmlns=\\\"http://www.w3.org/1999/xhtml\\\" num_fields=\\\"1\\\"><field name=\\\"property name\\\"></field></mutation>\",\"fields\":{\"field1\":\"payload\"},\"kind\":\"BLOCK\"}","{\"type\":\"node_return_message\",\"fields\":{\"OUTPUT_NR\":\"1\"},\"inputs\":{\"MESSAGE_INPUT\":{\"shadow\":{\"type\":\"node_msg\"}}},\"kind\":\"BLOCK\"}","{\"type\":\"node_object_set\",\"inline\":true,\"inputs\":{\"object_field\":{\"shadow\":{\"type\":\"node_msg\"}},\"field_name\":{\"shadow\":{\"type\":\"text\",\"fields\":{\"TEXT\":\"payload\"}}},\"value_field\":{\"shadow\":{\"type\":\"text\",\"fields\":{\"TEXT\":\"\"}}}},\"kind\":\"BLOCK\"}","{\"type\":\"node_object_get\",\"extraState\":\"<mutation xmlns=\\\"http://www.w3.org/1999/xhtml\\\" action=\\\"GET\\\"></mutation>\",\"fields\":{\"action\":\"GET\"},\"inputs\":{\"object\":{\"shadow\":{\"type\":\"node_msg\"}},\"field_name\":{\"shadow\":{\"type\":\"text\",\"fields\":{\"TEXT\":\"payload\"}}}},\"kind\":\"BLOCK\"}"],"toolboxPosition":"left","renderer":"geras","theme":"classic","categories":[{"name":"Node-RED","files":["blockly-contrib/npm/node-red-contrib-blockly/lib/nodered/nodeRedBlocksCodeGen.js","blockly-contrib/npm/node-red-contrib-blockly/lib/nodered/nodeRedBlocksDefs.js","blockly-contrib/npm/node-red-contrib-blockly/lib/nodered/toolbox.xml","blockly-contrib/npm/node-red-contrib-blockly/messages/en.js"]},{"name":"Objects","files":["blockly-contrib/npm/node-red-contrib-blockly/lib/json/objectBlocksCodeGen.js","blockly-contrib/npm/node-red-contrib-blockly/lib/json/objectBlocksDefs.js","blockly-contrib/npm/node-red-contrib-blockly/lib/json/toolbox.xml","blockly-contrib/npm/node-red-contrib-blockly/messages/en.js"]},{"name":"Buffer","files":["blockly-contrib/npm/node-red-contrib-blockly/lib/buffer/bufferBlocksCodeGen.js","blockly-contrib/npm/node-red-contrib-blockly/lib/buffer/bufferBlocksDefs.js","blockly-contrib/npm/node-red-contrib-blockly/lib/buffer/toolbox.xml","blockly-contrib/npm/node-red-contrib-blockly/messages/en.js"]},{"name":"Date/time","files":["blockly-contrib/npm/@blockly%2Ffield-date/dist/date_compressed.js","blockly-contrib/npm/node-red-contrib-blockly/lib/datetime/dateTimeBlocksCodeGen.js","blockly-contrib/npm/node-red-contrib-blockly/lib/datetime/dateTimeBlocksDefs.js","blockly-contrib/npm/node-red-contrib-blockly/lib/datetime/toolbox.xml","blockly-contrib/npm/node-red-contrib-blockly/messages/en.js"]},{"name":"Timer","files":["blockly-contrib/npm/node-red-contrib-blockly/lib/timer/timerBlocksCodeGen.js","blockly-contrib/npm/node-red-contrib-blockly/lib/timer/timerBlocksDefs.js","blockly-contrib/npm/node-red-contrib-blockly/lib/timer/toolbox.xml","blockly-contrib/npm/node-red-contrib-blockly/messages/en.js"]},{"name":"Blockly extension","files":["blockly-contrib/npm/node-red-contrib-blockly/lib/extra/extraBlocksCodeGen.js","blockly-contrib/npm/node-red-contrib-blockly/lib/extra/extraBlocksDefs.js","blockly-contrib/npm/node-red-contrib-blockly/lib/extra/toolbox.xml","blockly-contrib/npm/node-red-contrib-blockly/messages/en.js"]},{"name":"Blockly standard","files":["blockly-contrib/npm/node-red-contrib-blockly/lib/basic/toolbox.xml"]}],"customizeToolbox":false,"name":""}]
Inject a message via "Create vars".
You can see that the vars have been created at all 3 levels:
Inject a message via "Delete vars".
Now you can see that the vars have been created at all 3 levels:
SO EVERYTHING WORKS FINE!
But I admit it is confusing. However it is your lucky day, because 'somebody' has asked the same question on Discourse. And Nick has supplied an answer on the guy's question (see here). If you still don't understand it, I would contact that original poster if I were you...
Summarized this statement:
flow.set('payload')
Is the same as this statement:
flow.set('payload', undefined)
Because in the first statement you set a value, but you don't specify which value (so in fact the value will be undefined...).
But the latter statement is indeed more clear...
But although it works fine, I agree our generated code should be as self-explaining as possible. So I have pushed a fix to the master branch to generate this code from now on:
Thanks for the clarification :)
I couldn't seem to delete a flow.context property so when I looked at the JS to see what it was doing - I thought -aha - I see the problem
But, as usual, it must have got something else wrong :)
This one has probably been around for a while but not noticed until today! :)
is giving![image](https://github.com/bartbutenaers/node-red-contrib-blockly/assets/2357428/fd0e543e-0dec-416d-97d8-fc3ad770ad0e)
Only msg context working properly