Function that dumps all context.global vars to debug window

Crude functions to dump all context.global vars to debug pane. Dumps arrays and objects to one child level. Also function to delete all/individual context.global var/s

[{"id":"26917602.d96e8a","type":"inject","name":"trigger","topic":"","payload":"","payloadType":"string","repeat":"","crontab":"","once":false,"x":274,"y":163,"z":"1115f4b3.eeea0b","wires":[["3d0110db.c2fef"]]},{"id":"3d0110db.c2fef","type":"function","name":"dump: context.global ","func":"// dumps all vars in context.global \nvar objs = \"context.global: \";\n\nfor(var index in context.global) { \n   if(typeof context.global[index] == \"object\"){\n     \tobjs +=  \" \" + showKeys(index,context.global[index]);\n\t} else {\n\t   objs += \" \"+ index+\":\"+context.global[index]+\" , \"; \n\t}\n}\n\nfunction showKeys(parent,keys){\n   \tvar tkeys=\"\";\n   \tfor(var subIndex in keys) { \n\t\tif(typeof context.global[parent][subIndex] == \"object\"){\t\t\n\t\t\ttkeys += \" \"+ showKeysKeys(subIndex,context.global[parent][subIndex],parent);\n\t\t} else {\n\t\t\ttkeys += \" \"+ parent+\".\"+subIndex+\": \"+context.global[parent][subIndex]+\", \";\t\n\t\t}\n\t}\n\treturn tkeys;\n}\n\nfunction showKeysKeys(parent,keys,pp){\n   \tvar tkeys =\"\";\n   \tfor(var subIndex in keys) { \n\t\t\ttkeys += \" \"+pp+\".\"+parent+\".\"+subIndex+\": \"+context.global[pp][parent][subIndex]+\", \";\t\n\t}\n\treturn tkeys;\n}\n\nmsg.payload = objs;\nreturn msg;","outputs":1,"x":516,"y":162,"z":"1115f4b3.eeea0b","wires":[["870a5c65.78f5a"]]},{"id":"870a5c65.78f5a","type":"debug","name":"show","active":true,"console":"false","complete":"payload","x":733,"y":162,"z":"1115f4b3.eeea0b","wires":[]},{"id":"d314beef.2ceb4","type":"inject","name":"delete var","topic":"all","payload":"","payloadType":"string","repeat":"","crontab":"","once":false,"x":270,"y":198,"z":"1115f4b3.eeea0b","wires":[["b6240402.49dbf8"]]},{"id":"4fbef425.b0410c","type":"function","name":"Set vars example","func":"context.global.myvar = \"foo\";\ncontext.global.myarry = [\"foo\",\"/\",\"bar\"];\ncontext.global.debug = context.global.debug || {state:0, statePrevious: {pa:1,pb:2,pc:3}, darry: [0,1,2,3] };","outputs":1,"x":516,"y":234,"z":"1115f4b3.eeea0b","wires":[["870a5c65.78f5a"]]},{"id":"71b65ee1.8e49a","type":"inject","name":"trigger","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":274,"y":235,"z":"1115f4b3.eeea0b","wires":[["4fbef425.b0410c"]]},{"id":"b6240402.49dbf8","type":"function","name":"delete vars from global.context","func":"// Delete vars\nif(msg.topic!=\"\"){ \n\tif(msg.topic.toLowerCase() == \"all\"){\n\t\tfor(var index in context.global) { \n\t\t\tdelete context.global[index];\n\t\t}\n\t} else {\n\t\tfor(var index in context.global) { \n\t\t\tif(index == msg.topic){\n\t\t\t\tdelete context.global[index];\n\t\t\t}\n\t\t}\n\t}\n}","outputs":1,"x":488,"y":197,"z":"1115f4b3.eeea0b","wires":[["870a5c65.78f5a"]]}]

Flow Info

Created 9 years, 9 months ago
Updated 4 years, 7 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x3)
  • inject (x3)

Tags

  • debug
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option