Created
September 4, 2012 20:29
-
-
Save bennlich/3626107 to your computer and use it in GitHub Desktop.
problematic use of firebase api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function watchPosition(agent) { | |
| agent.dataRef.child("coords").once("value", function(coords) { | |
| if (coords.val()) { | |
| console.log("Has coords!"); | |
| agent.dataRef.child("coords").on("value", function(coords) { | |
| var lat = coords.child("lat").val(); | |
| var lon = coords.child("lon").val(); | |
| var patch = getPatchAt(lat, lon, 3); | |
| if (patch) agent.setData("patch", patch.url); | |
| else agent.setData("patch", null); | |
| }); | |
| } | |
| else { | |
| console.log("Has no coords! Has lat and lon!"); | |
| agent.dataRef.child("lat").on("value", function(latSnapshot) { | |
| var lat = latSnapshot.val(); | |
| var lon = agent.data.lon; | |
| var patch = getPatchAt(lat, lon, 3); | |
| if (patch) agent.setData("patch", patch.url); | |
| else agent.setData("patch", null); | |
| }); | |
| agent.dataRef.child("lon").on("value", function(lonSnapshot) { | |
| var lat = agent.data.lat; | |
| var lon = lonSnapshot.val(); | |
| var patch = getPatchAt(lat, lon, 3); | |
| if (patch) agent.setData("patch", patch.url); | |
| else agent.setData("patch", null); | |
| }); | |
| } | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function watchPosition(agent) { | |
| agent.dataRef.child("coords").on("value", function(coords) { | |
| if (coords.val()) { | |
| var lat = coords.child("lat").val(); | |
| var lon = coords.child("lon").val(); | |
| var patch = getPatchAt(lat, lon, 3); | |
| if (patch) agent.setData("patch", patch.url); | |
| else agent.setData("patch", null); | |
| } | |
| else { | |
| console.log("Has no coords!") | |
| agent.dataRef.child("lat").on("value", function(latSnapshot) { | |
| if (latSnapshot.val()) { | |
| var lat = latSnapshot.val(); | |
| var lon = agent.data.lon; | |
| var patch = getPatchAt(lat, lon, 3); | |
| if (patch) agent.setData("patch", patch.url); | |
| else agent.setData("patch", null); | |
| } | |
| }); | |
| agent.dataRef.child("lon").on("value", function(lonSnapshot) { | |
| if (lonSnapshot.val()) { | |
| var lat = agent.data.lat; | |
| var lon = lonSnapshot.val(); | |
| var patch = getPatchAt(lat, lon, 3); | |
| if (patch) agent.setData("patch", patch.url); | |
| else agent.setData("patch", null); | |
| } | |
| }); | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment