Caret/js/util/text.js
Thomas Wilburn 742f96f644 Load configs and other text via getPackageDirectoryEntry()
Fixes #127
Turns out this isn't actually any faster, but it is cleaner and doesn't
clutter the console. We'll keep it for now.
2014-01-12 21:13:06 -08:00

33 lines
No EOL
780 B
JavaScript

define(function() {
var cache = {};
var directory = null;
return {
load: function(name, parentRequire, onLoad, config) {
if (name in cache) {
return onLoad(cache[name]);
}
var getFile = function() {
directory.getFile(name, {create: false}, function(entry) {
entry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function() {
cache[name] = reader.result;
onLoad(reader.result);
};
reader.readAsText(file);
});
});
};
if (directory) return getFile();
chrome.runtime.getPackageDirectoryEntry(function(dir) {
directory = dir;
getFile();
});
}
};
});