Created
June 8, 2012 15:23
-
-
Save toddpi314/2896141 to your computer and use it in GitHub Desktop.
Rich_Domain_Components_Loader
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
Namespace.Register('DeepElement.ThreeOneFour.Helpers.ComponentLoader'); | |
/* | |
* Asynchronous Loader for Components | |
*/ | |
DeepElement.ThreeOneFour.Helpers.ComponentLoader = new Class({ | |
instances: null, | |
initialize: function(instances) { | |
this.instances = instances; | |
}, | |
unload: function(successCallback, failureCallback) { | |
if (successCallback != null) { | |
var workQueue = new Queue(); | |
for (var i = 0; i <= this.instances.length - 1; i++) { | |
var instance = this.instances[i]; | |
if (instance != null) workQueue.enqueue(instance); | |
} | |
this.callInstance('unload', workQueue, successCallback, failureCallback); | |
} | |
}, | |
load: function(successCallback, failureCallback) { | |
if (successCallback != null) { | |
var workQueue = new Queue(); | |
for (var i = 0; i <= this.instances.length - 1; i++) { | |
var instance = this.instances[i]; | |
if (instance != null) workQueue.enqueue(instance); | |
} | |
this.callInstance('load', workQueue, successCallback, failureCallback); | |
} | |
}, | |
callInstance: function(functionName, workQueue, successCallback, failureCallback) { | |
if (!workQueue.isEmpty() && successCallback != null) { | |
var instance = workQueue.dequeue(); | |
var self = this; | |
instance[functionName](function() { | |
self.callInstance(functionName, workQueue, successCallback, failureCallback); | |
}, function() { | |
if (failureCallback != null) failureCallback(); | |
}); | |
} else { | |
successCallback(); | |
} | |
}, | |
getInstances: function() { | |
return this.instances; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment