This function is intended to be a facade for requirejs's define
It provides a more descriptive name and creates a more vcs friends interface:
Compare (pseudocode):
runWithDepedencies = function( dependencyNames, callable(depedencies) )
to
define = function (name, deps, callback(dep1, dep2 etc) {
Consider (js):
define(['util', 'http', 'msg'], function (util, http, msg) {
}
Every time two people change dependencies, merge conflict.
var dependencies = [
'util',
'http',
'msg'
];
define( dependencies, function (util, http, msg) {
}
Better, but still a merge conflict.
var dependencies = [
'util',
'http',
'msg'
];
define( dependencies, function (
util,
http,
msg
) {
}
No merge conflicts, but but ass ugly
var dependencies = [
'util',
'http',
'msg'
];
runWithDependencies( dependencies, function (deps) {
// example usage of the msg dependency
deps.msg.someMethod();
// or assign to variables
var _ = deps.util;
var http = deps.util;
}
- Easy to scan and understand exactly what is happening
- Easy (don't reassign to var) to locate dependency usages (
desp.msg
is likely a unique string despite it being a three letter name) - No merge conflicts
perfect.
@awellsndt I wrote it. Still needs to be adjusted for deps as an object not array and include tests. Not really my priority right now, ill come back to it when im feeling motivated