Last active
September 29, 2016 08:40
-
-
Save ehgoodenough/97b078aebdb63df57468 to your computer and use it in GitHub Desktop.
This file contains 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
var Firebase = require("firebase") | |
class Leaderboard { | |
constructor(firebaseURL) { | |
this.firebase = new Firebase(firebaseURL) | |
this.firebase.orderByChild("score").limitToLast(5).on("value", (value) => { | |
this.scores = value.val() | |
}) | |
} | |
add(data) { | |
if(!data.name || data.name.length > 3) { | |
throw new Error("Requires a valid name.") | |
} else if(!data.score || isNaN(data.score)) { | |
throw new Error("Requires a valid score.") | |
} else { | |
this.firebase.push(data).setPriority(data.score) | |
} | |
} | |
get() { | |
return this.scores | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use it, just pass it a URL to your firebase.