Skip to content

Instantly share code, notes, and snippets.

@edtoken
Created October 9, 2016 16:38
Show Gist options
  • Save edtoken/4e5459683171a28e2f7bb55d89cc6938 to your computer and use it in GitHub Desktop.
Save edtoken/4e5459683171a28e2f7bb55d89cc6938 to your computer and use it in GitHub Desktop.
function readTextFiles(file, callback, ctx) {
ctx = ctx || this;
if (typeof file === 'object') {
var index = file.length;
var response = [];
for (var i = 0; i < file.length; i++) {
(function (f, i) {
readTextFiles(f, function (resp) {
response.splice(i, 0, resp);
index--;
if (!index) {
callback.apply(ctx, response);
}
})
})(file[i], i)
}
return;
}
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
};
rawFile.send(null);
}
readTextFiles([configFile, dataFile], function (configSource, dataSource) {
var config = JSON.parse(configSource);
var data = JSON.parse(dataSource);
var Customizer = new ReactCustomizer(config, data);
Customizer.render();
Customizer.onSubmit = function (data) {
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment