Skip to content

Instantly share code, notes, and snippets.

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