Skip to content

Commit

Permalink
Rename loader->receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jul 22, 2010
1 parent bf80bd6 commit 57c2f4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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 Now you can use a client side module loader like RequireJS, Yabble, or the simple loader
that comes with transporter to load your modules: 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> <script src="my-module.js"></script>


If my-module.js requires other modules (using a require call), these modules will If my-module.js requires other modules (using a require call), these modules will
Expand Down
4 changes: 2 additions & 2 deletions lib/jsgi/transporter.js
Expand Up @@ -54,8 +54,8 @@ exports.Transporter = function(options, app) {
}, },
body: { body: {
forEach: function(write){ forEach: function(write){
if(requestedModules[0] === "transporter/loader"){ if(requestedModules[0] === "transporter/receiver"){
write(loader("transporter/loader.js")); write(loader("transporter/receiver.js"));
requestedModules.shift(); requestedModules.shift();
} }
if(converter.start){ if(converter.start){
Expand Down
18 changes: 11 additions & 7 deletions lib/loader.js → lib/receiver.js
@@ -1,9 +1,10 @@
/** A very lightweight implementation of transport/D's require.define and /** 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(){ (function(){
var factories = {}, var factories = {},
loadedModules = {}; modules = {};
function makeRequire(currentId){ function makeRequire(currentId){
return function(id){ return function(id){
if(id.charAt(0) === '.'){ if(id.charAt(0) === '.'){
Expand All @@ -14,24 +15,27 @@
} }
id = id.replace(/\/\.\//g,'/'); id = id.replace(/\/\.\//g,'/');
} }
var module = loadedModules[id]; var module = modules[id];
if(module){ if(module){
return module; return module;
} }
if(!factories[id]){ 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){ if(module){
return loadedModules[id] = module; return modules[id] = module;
} }
return loadedModules[id]; return modules[id];
}; };
} }
require = { require = {
define: function(modules){ define: function(modules){
for(var i in modules){ for(var i in modules){
factories[i] = modules[i]; factories[i] = modules[i];
if(typeof factories[i] != "function"){
throw new Error("Module " + id + " must be defined as a function");
}
} }
}, },
ensure: function(modules, callback){ ensure: function(modules, callback){
Expand Down

0 comments on commit 57c2f4d

Please sign in to comment.