Created
February 14, 2014 17:15
-
-
Save Rolilink/9005040 to your computer and use it in GitHub Desktop.
Static way
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
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