Skip to content

Instantly share code, notes, and snippets.

@deleteme
Last active December 24, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deleteme/6877877 to your computer and use it in GitHub Desktop.
Save deleteme/6877877 to your computer and use it in GitHub Desktop.
// define ds, which adds to a queue
// must be included in <head>, before anything else.
function ds(){
(ds.q = ds.q || []).push(arguments);
return ds;
}
// process queue, included at the end of vendored js
function run(args){
var module = args[0]();
return ds[module.name] = module;
}
while (ds.q.length) {
run(ds.q.pop());
}
// redefine push to run the module async as soon as possible
ds.q.push = _.partial(_.defer, run);
// Example of page specific module
ds(function(){
var pub = { name: 'stuff' };
function doStuff(){}
$(function(){
$('.stuff').on('click', doStuff);
});
return pub;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment