Created
August 11, 2015 23:09
-
-
Save robwhitaker/513bf821cc012d70588f to your computer and use it in GitHub Desktop.
Just a simple utility class for some callback handling.
This file contains hidden or 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
function ReadyListener(config) { | |
this.properties = config || {}; | |
this.onReady = function() {}; | |
} | |
ReadyListener.prototype.ready = function(key) { | |
this.properties[key] === false && (this.properties[key] = true); | |
var isReady = true; | |
for(k in this.properties) isReady = isReady && this.properties[k]; | |
isReady && this.onReady(); | |
} | |
ReadyListener.prototype.then = function(callback) { | |
this.onReady = callback; | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment