Created
February 14, 2014 17:09
-
-
Save Rolilink/9004960 to your computer and use it in GitHub Desktop.
Loading Modules Dynamically
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(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