Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of http://github.com/kriszyp/transporter

Conflicts:
	lib/receiver.js
  • Loading branch information...
commit f15e2a57cfacee138730aeaf2cf9694c128992db 2 parents f287647 + b4978ac
@dvv dvv authored
View
2  README.md
@@ -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
4 lib/jsgi/transporter.js
@@ -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){
View
22 lib/loader.js → lib/receiver.js
@@ -1,9 +1,16 @@
+<<<<<<< HEAD:lib/loader.js
/** A very lightweight implementation of transport/D's require.define and
* require.ensure
+=======
+/** A very lightweight implementation of transport/D's require.define and
+ * require.ensure. This can only receive modules, it will not proactively attempt to load
+ * any modules, so you must not turn off the default transporter setting of
+ * resolveDeps to use this module receiver.
+>>>>>>> b4978ac0c691f957c2d46eb18aecc84ae5351cc8:lib/receiver.js
*/
(function(){
var factories = {},
- loadedModules = {};
+ modules = {};
function makeRequire(currentId){
return function(id){
if(id.charAt(0) === '.'){
@@ -14,24 +21,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){
Please sign in to comment.
Something went wrong with that request. Please try again.