Skip to content

Instantly share code, notes, and snippets.

@neonstalwart
Created February 1, 2011 21:19
Show Gist options
  • Save neonstalwart/806707 to your computer and use it in GitHub Desktop.
Save neonstalwart/806707 to your computer and use it in GitHub Desktop.
requirejs sync plugin loading support
diff --git a/require.js b/require.js
old mode 100644
new mode 100755
index 9147d58..4341bad
--- a/require.js
+++ b/require.js
@@ -254,7 +254,7 @@ var require, define;
if (prefix) {
prefix = normalize(prefix, parentName);
//Allow simpler mappings for some plugins
- prefix = requirePlugins[prefix] || prefix;
+ prefix = prefix || requirePlugins[prefix];
}
//Account for relative paths if there is a base name.
@@ -845,6 +845,17 @@ var require, define;
}, config);
}
+ function callPluginSync(moduleMap) {
+ var ret; // this will be the return value
+
+ plugins[moduleMap.prefix].load(moduleMap.name, makeRequire(moduleMap.parentMap, true),
+ function (value) {
+ ret = value;
+ });
+
+ return ret;
+ }
+
function loadPaused(dep) {
//Renormalize dependency if its name was waiting on a plugin
//to load, which as since loaded.
@@ -1082,7 +1093,7 @@ var require, define;
//Normalize module name, if it contains . or ..
moduleMap = makeModuleMap(moduleName, relModuleMap);
- ret = defined[moduleMap.fullName];
+ ret = defined[moduleMap.fullName] || callPluginSync(moduleMap);
if (ret === undefined) {
return req.onError(new Error("require: module name '" +
moduleMap.fullName +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment