Created
November 26, 2014 21:49
-
-
Save chiquitinxx/5192ff81d3b3351e3f1d to your computer and use it in GitHub Desktop.
Using Firebase from your pages in a Groovy way with grooscript
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
def firebase = new GrooscriptFirebase() | |
firebase.message = [list: [1, 2, 3], number: 5, name: 'grooscript'] | |
//Show on console: | |
// Message received: [list: [1, 2, 3] ,name: grooscript ,number: 5 ,] | |
class GrooscriptFirebase extends BaseFirebase { | |
GrooscriptFirebase() { | |
super('https://XXXX.firebaseio.com/') | |
} | |
def onMessage(data) { | |
println "Message received: $data" | |
} | |
} | |
class BaseFirebase { | |
def dataRef | |
BaseFirebase(String url) { | |
initFirebase(url) | |
this.metaClass.methods.each { it -> | |
if (it.name.startsWith('on')) { | |
def nameProperty = it.name.substring(2).toLowerCase() | |
doOnEvent(nameProperty, it.name) | |
} | |
} | |
} | |
@GsNative | |
void setProperty(String name, value) {/* | |
this.dataRef.child(name).set(gs.toJavascript(value)); | |
*/} | |
@GsNative | |
private initFirebase(String url) {/* | |
this.dataRef = new Firebase(url); | |
*/} | |
@GsNative | |
private doOnEvent(String name, String nameMethod) {/* | |
gSobject.dataRef.child(name).on('value', function(snapshot) { | |
gSobject[nameMethod](gs.toGroovy(snapshot.val())); | |
}); | |
*/} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment