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

Unified Diff: lib/io.js

Issue 29760680: Issue 4580 - Removed ext.storage (Closed)
Patch Set: Created April 24, 2018, 5:18 p.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 | « ext/background.js ('k') | lib/prefs.js » ('j') | lib/prefs.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/io.js
===================================================================
--- a/lib/io.js
+++ b/lib/io.js
@@ -26,48 +26,23 @@
function loadFile(fileName)
{
- return new Promise((resolve, reject) =>
+ let key = fileToKey(fileName);
+ return browser.storage.local.get(key).then(items =>
{
- let key = fileToKey(fileName);
-
- ext.storage.get(key, items =>
- {
- let entry = items[key];
-
- if (entry)
- resolve(entry);
- else
- reject({type: "NoSuchFile"});
- });
+ let entry = items[key];
+ if (entry)
+ return entry;
+ throw {type: "NoSuchFile"};
kzar 2018/04/24 20:38:56 Don't we normally throw an Error instance? (I get
Sebastian Noack 2018/04/24 21:12:55 Yeah, I had a similar WTF moment when I converted
kzar 2018/04/25 10:33:39 Acknowledged.
});
}
function saveFile(fileName, data)
{
- return new Promise((resolve, reject) =>
- {
- ext.storage.set(
- fileToKey(fileName),
- {
- content: Array.from(data),
- lastModified: Date.now()
- },
- resolve
- );
- });
-}
-
-function removeFile(fileName)
-{
- return new Promise((resolve, reject) =>
- {
- ext.storage.remove(fileToKey(fileName), () =>
- {
- if (browser.runtime.lastError)
- reject(browser.runtime.lastError.message);
- else
- resolve();
- });
+ return browser.storage.local.set({
+ [fileToKey(fileName)]: {
+ content: Array.from(data),
+ lastModified: Date.now()
+ }
});
}
@@ -131,19 +106,9 @@
*/
renameFile(fromFile, newName)
{
- return loadFile(fromFile).then(entry =>
- {
- return new Promise((resolve, reject) =>
- {
- ext.storage.set(fileToKey(newName), entry, () =>
- {
- if (browser.runtime.lastError)
- reject(browser.runtime.lastError.message);
- else
- resolve();
- });
- });
- }).then(() => removeFile(fromFile));
+ return loadFile(fromFile)
+ .then(entry => browser.storage.local.set({[fileToKey(newName)]: entry}))
+ .then(() => this.removeFile(fromFile));
},
/**
@@ -155,7 +120,7 @@
*/
removeFile(fileName)
{
- return removeFile(fileName);
+ return browser.storage.local.remove(fileToKey(fileName));
},
/**
« no previous file with comments | « ext/background.js ('k') | lib/prefs.js » ('j') | lib/prefs.js » ('J')

Powered by Google App Engine
This is Rietveld