Skip to content

Instantly share code, notes, and snippets.

@zobalogh
Created October 22, 2014 17:00
Show Gist options
  • Save zobalogh/5d04e13a1da067fe9b8d to your computer and use it in GitHub Desktop.
Save zobalogh/5d04e13a1da067fe9b8d to your computer and use it in GitHub Desktop.
Global Location Context Storer flow
[{"id":"c9b7b9dd.364848","type":"instagram","instagram":"","inputType":"like","outputType":"link","name":"","x":351,"y":300,"z":"da79d491.258628","wires":[["7cca3aa6.8335c4"]]},{"id":"78a76c3f.875894","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":151,"y":301,"z":"da79d491.258628","wires":[["c9b7b9dd.364848"]]},{"id":"7cca3aa6.8335c4","type":"function","name":"Store Location Globally","func":"// only store location if it's new\nif(msg.lat && msg.lon && msg.time) { // do something\n if(msg.lastGlobalLoc) { // if we're dealing with last known global loc\n if(msg.time > context.time) {\n // nothing to store as the global time of location is more recent\n } else {\n // need to update global location\n context.global.lat = context.lat;\n context.global.lon = context.lon;\n context.global.time = context.time;\n }\n return msg;\n } else { // normal exec, initial steps\n msg.fromStorer = true; // indicate to global location querier that we're the storer\n \n // store the data we received temporarily in case it's new and we need to use it\n context.lat = msg.lat;\n context.lon = msg.lon;\n context.time = msg.time;\n \n\t\treturn msg;\n }\n} ","outputs":"1","x":596,"y":235,"z":"da79d491.258628","wires":[["7394426b.8c6bbc"]]},{"id":"7394426b.8c6bbc","type":"function","name":"Send known global location","func":"if(msg.fromStorer && msg.fromStorer === true) { // need to talk to storer\n\tmsg.lat = context.global.lat;\n\tmsg.lon = context.global.lon;\n\tmsg.time = context.global.time;\n\tmsg.lastGlocalLoc = true;\n\n\tvar msgToReturn = [];\n\t\n\tmsgToReturn[0] = msg;\n\tmsgToReturn[1] = null;\n\t\n\treturn msgToReturn;\n} else { // simple retrieve\n\tmsg.lat = context.global.lat;\n\tmsg.lon = context.global.lon;\n\tmsg.time = context.global.time;\n\t\n\tvar msgToReturn = [];\n\t\n\tmsgToReturn[0] = null;\n\tmsgToReturn[1] = msg;\n\t\n\treturn msgToReturn;\n}","outputs":"2","x":731,"y":80,"z":"da79d491.258628","wires":[["7cca3aa6.8335c4"],["60242408.9fdbdc"]]},{"id":"60242408.9fdbdc","type":"debug","name":"","active":true,"console":"false","complete":"false","x":1031,"y":200,"z":"da79d491.258628","wires":[]},{"id":"2c5bacbf.d3a454","type":"comment","name":"Only stores location => keeps it modular","info":"","x":613,"y":281,"z":"da79d491.258628","wires":[]},{"id":"a960caf9.569f38","type":"comment","name":"Only retrieves global location => keeps it modular","info":"","x":728,"y":35,"z":"da79d491.258628","wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment