Created
January 13, 2016 21:45
-
-
Save freekrai/376960715a63ff286e82 to your computer and use it in GitHub Desktop.
Flybase deffered
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
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script> | |
<script src="https://cdn.flybase.io/flybase.js?20151206"></script> | |
</head> | |
<body> | |
<script> | |
var FB = function(){ | |
var Ref = new Flybase("API-KEY", "sample", "chat"); | |
} | |
FB.prototype.on = function(event){ | |
var deferred = $.Deferred(); | |
var _this = this; | |
this.flybaseRef.on(event,function( data ){ | |
if( data.count() !== null ){ | |
deferred.resolve( data ); | |
}else{ | |
deferred.reject( null ); | |
} | |
}); | |
return deferred.promise(); | |
}; | |
FB.prototype.once = function(event){ | |
var deferred = $.Deferred(); | |
var _this = this; | |
this.flybaseRef.once(event,function( data ){ | |
if( data.count() !== null ){ | |
deferred.resolve( data ); | |
}else{ | |
deferred.reject( null ); | |
} | |
}); | |
return deferred.promise(); | |
}; | |
FB.on('added').then(function( data ){ | |
console.log( data.value() ); | |
}); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment