-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase-sampler.html
64 lines (46 loc) · 1.73 KB
/
firebase-sampler.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<title>Firebase Sampler Platter</title>
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
<style>
</style>
</head>
<body>
</body>
<script type="text/javascript">
var firebaseRef = new Firebase('https://eat-tools.firebaseio.com/');
//This is where the first person who visits the app gets the global GUID for the group is set. Could also be done with a push() and read the server side generated GUID.
var globalRef = firebaseRef.child("guid456");
///////////////////////////////Set Sampler////////////////////////////////////////////////
// This pattern is used to write the whole object. When a new user is joinging, the object gets overwritten after localstorage, sessionstorage, or cookies are checked.
// globalRef.set({
// player1:123,
// player2:456,
// player3:567,
// player4:789,
// player5:901,
// player6:123
// })
///////////////////////////////Update Sampler////////////////////////////////////////////////
// How an individual value can be updated
// globalRef.update({
// player6:321
// })
///////////////////////////////Push Sampler////////////////////////////////////////////////
// High volume writes pattern
// var uniqueRef = globalRef.push({
// player:789
// });
// // Get the unique ID generated by push()
// var newPushID = uniqueRef.key();
// console.log(newPushID);
///////////////////////////////Read Sampler////////////////////////////////////////////////
// How to retrieve values. Attach an asynchronous callback to read the data at our global reference.
globalRef.on("value", function(snapshot) {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
</script>
</html>