Skip to content

Instantly share code, notes, and snippets.

@nathanaelnsmith
Last active April 15, 2016 00:45
Show Gist options
  • Save nathanaelnsmith/1027c49637045d0a0b33fe265ac176ae to your computer and use it in GitHub Desktop.
Save nathanaelnsmith/1027c49637045d0a0b33fe265ac176ae to your computer and use it in GitHub Desktop.
/*
* Author: Nathanael Smith
* Description: This module stores functions in a run queue until they're needed to be executed.
*/
var ExeQue = (function(){
function store (location, func) {
var queue = getQueue(location).concat(func);
if (location instanceof jQuery) {
location.data('ExeQue', queue);
} else {
location.ExeQue = queue;
}
return queue;
}
function execute (location) {
var queue = getQueue(location);
for(var i = 0; i < queue.length; i++) {
queue[i]();
}
deleteQueue(location);
return true;
}
function getQueue (location) {
return (location instanceof jQuery ? location.data('ExeQue') : location.ExeQue) || [];
}
function deleteQueue (location) {
if (location instanceof jQuery) {
$.removeData(location, 'ExeQue');
} else {
delete location.ExeQue;
}
}
return {
store: store,
execute: execute
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment