Created
September 2, 2016 08:39
-
-
Save nathanchicken/3983f7a2a0de93d939611006d4129186 to your computer and use it in GitHub Desktop.
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
APP.initialiser = { | |
// use as keywords, add to a 'global' fn queue, and decide when the 'global' queue is ready to execute. | |
keys: ['global', 'shop', 'photoswipe'], | |
statuses: {}, | |
add: function( when, fn ) { | |
// you don't get to pass arguments to the init queue! | |
// do we have this status object? | |
// if not then there's no queue set thus we aren't | |
// expecting anything to resolve this... | |
if ( !this.statuses.hasOwnProperty( when ) ) { | |
fn(); | |
return; | |
} | |
var obj = this.statuses[when]; | |
if (obj.status === "pending") { | |
// we're not ready yet, store in the q | |
obj.fnQ.push( fn ); | |
} else { | |
fn(); | |
} | |
}, | |
start: function( when ) { | |
if ( !this.statuses.hasOwnProperty( when ) ) { | |
return; | |
} | |
console.log("starting " + when); | |
var obj = this.statuses[when]; | |
if (obj.status === "pending") { | |
obj.fnQ.forEach( function( fn, i ) { | |
console.log('running ' + i); | |
fn(); | |
}); | |
// for extra security, empty out the functions: | |
obj.fnQ = []; | |
// and set the status to done | |
obj.status = "done"; | |
} | |
} | |
}; | |
APP.initialiser.keys.forEach( function( key ) { | |
APP.initialiser.statuses[key] = { | |
fnQ: [], | |
status: "pending" | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment