Skip to content

Instantly share code, notes, and snippets.

@tbranyen
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbranyen/9839306 to your computer and use it in GitHub Desktop.
Save tbranyen/9839306 to your computer and use it in GitHub Desktop.
JSON AMD Loader
define("json", function(require, exports) {
"use strict";
// Cache used to map configuration options between load and write.
var buildMap = {};
load: function(name, req, load, config) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (config.isBuild) {
return load();
}
load(buildMap[name] = JSON.parse(xhr.responseText));
}
};
xhr.open("GET", req.toUrl(name), true);
xhr.send(null);
},
write: function(pluginName, moduleName, write) {
var stringified = JSON.stringify(buildMap[moduleName]);
write(["define('", pluginName, "!", moduleName, "', ", stringified]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment