Skip to content

Instantly share code, notes, and snippets.

@Rolilink
Created February 14, 2014 17:09
Show Gist options
  • Save Rolilink/9004960 to your computer and use it in GitHub Desktop.
Save Rolilink/9004960 to your computer and use it in GitHub Desktop.
Loading Modules Dynamically
define(function(require){
var runFilters = function(filters){
var _ = require('underscore');
var computedFilters = getFilters(filters);
var result = _.every(computedFilters,function(filter){
return filter();
});
return result;
};
var getFilters = function(filters){
var _ = require('underscore');
return _.map(filters,function(filter){
return require('filters/' + filter);
},this);
}
var register = function(filters,fn){
return function(){
var args = Array.prototype.slice.apply(arguments);
if(runFilters(filters))
cb.apply(this,args);
}
}
return{
register: register
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment