Skip to content

Instantly share code, notes, and snippets.

@freekrai
Created January 13, 2016 21:45
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 freekrai/376960715a63ff286e82 to your computer and use it in GitHub Desktop.
Save freekrai/376960715a63ff286e82 to your computer and use it in GitHub Desktop.
Flybase deffered
<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