forked from persvr/persevere-example-wiki
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add public/receiver.js from transporter until i can figure out how to…
… reference it properly
- Loading branch information
1 parent
1e804e7
commit 7043ad5
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** A very lightweight implementation of CommonJS Asynchronous Module Definition | ||
* (require.def) and | ||
* require.ensure. This can only receive modules, it will not proactively attempt to load | ||
* any modules, so you must leave the default transporter setting of | ||
* resolveDeps on (true) to use this module receiver. | ||
*/ | ||
(function(){ | ||
var factories = {}, | ||
modules = {}; | ||
function req(id){ | ||
var module = modules[id]; | ||
if(module){ | ||
return module; | ||
} | ||
if(!factories[id]){ | ||
throw new Error("Module " + id + " not found"); | ||
} | ||
var factory = factories[id]; | ||
var args = factory.deps || (factory.length ? ["require", "exports", "module"] : []); | ||
var exports = modules[id] = {}; | ||
for(var i = 0; i < args.length; i++){ | ||
var arg = args[i]; | ||
switch(arg){ | ||
case "require": arg = function(relativeId){ | ||
if(relativeId.charAt(0) === '.'){ | ||
relativeId = id.substring(0, id.lastIndexOf('/') + 1) + relativeId; | ||
while(lastId !== relativeId){ | ||
var lastId = relativeId; | ||
relativeId = relativeId.replace(/\/[^\/]*\/\.\.\//,'/'); | ||
} | ||
relativeId = relativeId.replace(/\/\.\//g,'/'); | ||
} | ||
return req(relativeId); | ||
}; break; | ||
case "exports": arg = exports; break; | ||
case "module": var module = arg = {exports: exports}; break; | ||
default: arg = req(arg); | ||
} | ||
args[i] = arg; | ||
} | ||
|
||
exports = factory.apply(this, args); | ||
if(module && module.exports != modules[id]){ | ||
exports = module.exports; | ||
} | ||
if(exports){ | ||
return modules[id] = exports; | ||
} | ||
return modules[id]; | ||
} | ||
define = function(id, deps, factory){ | ||
if(typeof deps == "function"){ | ||
factories[id] = deps; | ||
}else{ | ||
(factories[id] = factory).deps = deps; | ||
} | ||
}; | ||
|
||
require = { | ||
ensure: function(modules, callback){ | ||
for(var i = 0; i < modules.length; i++){ | ||
modules = req(modules[i]); | ||
} | ||
callback(req); | ||
} | ||
}; | ||
})(); |
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