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.
This commit is contained in:
parent
6f762a9e59
commit
742f96f644
1 changed files with 19 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
|||
define(function() {
|
||||
|
||||
var cache = {};
|
||||
var directory = null;
|
||||
|
||||
return {
|
||||
load: function(name, parentRequire, onLoad, config) {
|
||||
|
@ -8,12 +9,24 @@ define(function() {
|
|||
return onLoad(cache[name]);
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", name);
|
||||
xhr.onload = xhr.onerror = function() {
|
||||
onLoad(xhr.responseText);
|
||||
}
|
||||
xhr.send();
|
||||
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();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue