-
Notifications
You must be signed in to change notification settings - Fork 2
/
ADeferredModule.js
47 lines (34 loc) · 1.3 KB
/
ADeferredModule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* App Deferred Module Abstract Class
*
* @author Max Maximov <[email protected]>
* @version 0.2.1
*/
define( ["./Hub", "./Logger", "./IModule"], function (Hub, Logger, IModule) {
"use strict";
app.IModule.extend("app.ADeferredModule",
/* @prototype */
{
_readyCallbacks: undefined,
setup: function(){
this._readyCallbacks = [];
},
onReady: function ( callback, runOnce ) {
runOnce = runOnce === undefined ? true : runOnce;
if( typeof callback !== "function" ) throw new Error("callback must be function");
this._readyCallbacks.push({ runOnce: runOnce, callback: callback });
},
setReady: function(){
var len = this._readyCallbacks.length;
while( len-- ) {
if( this._readyCallbacks[len].callback !== undefined && typeof this._readyCallbacks[len].callback == "function" ) {
this._readyCallbacks[len].callback();
}
if( this._readyCallbacks[len].runOnce !== false ) {
this._readyCallbacks.splice(len, 1);
}
}
}
});
return app.ADeferredModule;
});