Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/io.js

Issue 29367480: Issue 4721 - Use IndexedDB for storage in Edge (Closed)
Patch Set: Don't introduce unnecessary changes from old code Created Dec. 19, 2016, 10:55 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/localforage.min.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/io.js
===================================================================
--- a/lib/io.js
+++ b/lib/io.js
@@ -25,32 +25,45 @@
function loadFile(file, successCallback, errorCallback)
{
let key = fileToKey(file);
-
- ext.storage.get([key], function(items)
+ // Make sure we do not have subscriptions in localStorage from older
+ // versions first
+ let entry = localStorage.getItem(key);
+ if (typeof entry == "string")
{
- let entry = items[key];
-
- if (entry)
- successCallback(entry);
+ try
+ {
+ entry = JSON.parse(entry);
+ }
+ catch(err)
+ {
+ setTimeout(errorCallback(new Error("File is corrupted")));
+ return;
+ }
+ setTimeout(successCallback(entry));
+ return;
+ }
+ // Now try to read from IndexedDB
+ localforage.getItem(key, function(err, value)
+ {
+ if (err || !value)
+ errorCallback(new Error("File doesn't exist"));
else
- errorCallback(new Error("File doesn't exist"));
+ successCallback(value);
});
}
function saveFile(file, data, callback)
{
- ext.storage.set(
- fileToKey(file),
- {
- content: Array.from(data),
- lastModified: Date.now()
- },
- callback
- );
+ var key = fileToKey(file);
+ var entry = {
+ lastModified: Date.now(),
+ content: Array.from(data)
+ };
+
+ localStorage.removeItem(key);
+ localforage.setItem(key, entry, callback);
}
-
-exports.IO =
-{
+exports.IO = {
kzar 2016/12/19 13:31:04 Nit: looks like you missed this change, please cou
resolveFilePath: function(path)
{
return new FakeFile(path);
@@ -60,9 +73,11 @@
{
function onLoaded(entry)
{
- for (let line of entry.content)
- listener.process(line);
-
+ if ("content" in entry)
+ {
+ for (let line of entry.content)
+ listener.process(line);
+ }
listener.process(null);
callback(null);
}
@@ -82,7 +97,7 @@
saveFile(toFile, entry.content, callback);
}
- loadFile(fromFile, onLoaded, callback);
+ loadFile(file, onLoaded, callback);
kzar 2016/12/19 13:31:04 Seems to be a mistake? (Same below.)
Oleksandr 2016/12/20 00:18:28 Yep. We don't use any of these functions anyway, s
},
renameFile: function(fromFile, newName, callback)
@@ -95,7 +110,7 @@
});
}
- loadFile(fromFile, onLoaded, callback);
+ loadFile(file, onLoaded, callback);
},
removeFile: function(file, callback)
« no previous file with comments | « no previous file | lib/localforage.min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld