Last active
August 29, 2015 13:57
-
-
Save tbranyen/9839306 to your computer and use it in GitHub Desktop.
JSON AMD Loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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