Skip to content

Instantly share code, notes, and snippets.

@chiquitinxx
Created November 26, 2014 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiquitinxx/5192ff81d3b3351e3f1d to your computer and use it in GitHub Desktop.
Save chiquitinxx/5192ff81d3b3351e3f1d to your computer and use it in GitHub Desktop.
Using Firebase from your pages in a Groovy way with grooscript
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