Hi @Steve-Mcl
Thanks
By "stored" I meant "stored to filesystem" as I have configured the context to be stored by default to filesystem. Actually I am storing in (flow.)context values that are critical and that should be preserved in case node-red restarts.
But I have 2 other use-cases:
- Case 1 : constants such as mapping tables. Those need to be set once for all at deploy/start of NR and doesn't need to be modified by code. I know about the improvement of the editor, great addition. But beside that, it was working in v2 to declare those kind of variables in "On Start" even not specifying
var
or const
.
- Case 2 : non critical values that I'm using more for debug and I don't care to loose in case of reboot
For those case, I feel that using context.xxx()
API is a bit "too much" and remove the flexibility of using the values directly as variables/members without having the seed to call for get()
and set()
Here is a simple message counter exempl where I solved the situation using this.
This is what I meant by "simple variables". Something that I can use directly and not through API calls
Still I don't understand why it is enough to use this.
only once in "On Start" and once in "On Message" and not every time.
[{"id":"3ae3f90e6c815dd6","type":"function","z":"bbbd97e84cc4a26b","name":"counter","func":"if (msg.reset) {\n this.counter = 0;\n node.status({ fill: \"blue\", shape: \"dot\", text: `${counter}` })\n return null;\n}\ncounter = counter + 1\nnode.status({ fill: \"blue\", shape: \"dot\", text: `${counter}` })\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\nthis.counter = 0\nnode.status({ fill: \"blue\", shape: \"dot\", text: `${counter}` })\n","finalize":"","libs":[],"x":440,"y":7220,"wires":[["a299c77d20d6cf41"]]},{"id":"279a9df6434c4ce7","type":"inject","z":"bbbd97e84cc4a26b","name":"count","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":7200,"wires":[["3ae3f90e6c815dd6"]]},{"id":"be8c87b4ab52342a","type":"inject","z":"bbbd97e84cc4a26b","name":"reset","props":[{"p":"reset","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":7240,"wires":[["3ae3f90e6c815dd6"]]},{"id":"a299c77d20d6cf41","type":"debug","z":"bbbd97e84cc4a26b","name":"debug 211","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":7220,"wires":[]}]
I would be pleased to get your review and comments
Thanks