Permalink
Browse files

Rename loader->receiver

  • Loading branch information...
1 parent bf80bd6 commit 57c2f4d0fd590bd56d9914741998b1849791f221 @kriszyp committed Jul 22, 2010
Showing with 14 additions and 10 deletions.
  1. +1 −1 README.md
  2. +2 −2 lib/jsgi/transporter.js
  3. +11 −7 lib/{loader.js → receiver.js}
View
@@ -19,7 +19,7 @@ To use transporter, include the appliance in your JSGI stack:
Now you can use a client side module loader like RequireJS, Yabble, or the simple loader
that comes with transporter to load your modules:
- <script src="transporter/loader.js"></script>
+ <script src="transporter/receiver.js"></script>
<script src="my-module.js"></script>
If my-module.js requires other modules (using a require call), these modules will
View
@@ -54,8 +54,8 @@ exports.Transporter = function(options, app) {
},
body: {
forEach: function(write){
- if(requestedModules[0] === "transporter/loader"){
- write(loader("transporter/loader.js"));
+ if(requestedModules[0] === "transporter/receiver"){
+ write(loader("transporter/receiver.js"));
requestedModules.shift();
}
if(converter.start){
@@ -1,9 +1,10 @@
/** A very lightweight implementation of transport/D's require.define and
- * require.ensure
+ * require.ensure. This can only receive modules, it will not proactively attempt to load
+ * any modules.
*/
(function(){
var factories = {},
- loadedModules = {};
+ modules = {};
function makeRequire(currentId){
return function(id){
if(id.charAt(0) === '.'){
@@ -14,24 +15,27 @@
}
id = id.replace(/\/\.\//g,'/');
}
- var module = loadedModules[id];
+ var module = modules[id];
if(module){
return module;
}
if(!factories[id]){
- throw new Error("Module " + id + " not defined");
+ throw new Error("Module " + id + " not found");
}
- var module = factories[id](makeRequire(id), loadedModules[id] = {}, {});
+ var module = factories[id](makeRequire(id), modules[id] = {}, {});
if(module){
- return loadedModules[id] = module;
+ return modules[id] = module;
}
- return loadedModules[id];
+ return modules[id];
};
}
require = {
define: function(modules){
for(var i in modules){
factories[i] = modules[i];
+ if(typeof factories[i] != "function"){
+ throw new Error("Module " + id + " must be defined as a function");
+ }
}
},
ensure: function(modules, callback){

0 comments on commit 57c2f4d

Please sign in to comment.