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

Side by Side Diff: edge/ext/background.js

Issue 29367151: Issue 4721 - Use IndexedDB for storage in Edge (Closed)
Patch Set: Created Dec. 9, 2016, 6:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 (function()
19 {
20 /* Storage redirection to localforage */
kzar 2016/12/12 14:17:50 If you're going to add a comment here you might as
Oleksandr 2016/12/13 06:21:19 Done. There is no bug report in Microsoft Edge iss
21
22 ext.storage = {
23 get: function(keys, callback)
24 {
25 var promisedValues = keys.map(function(key)
kzar 2016/12/12 14:17:50 Why not just use localforage.getItem directly? Als
Oleksandr 2016/12/13 06:21:18 localForage.getItem can't handle the array of keys
kzar 2016/12/13 10:24:04 I know. I don't think I worded my suggestion very
26 {
27 return localforage.getItem(key);
28 });
29 Promise.all(promisedValues).then(function(values)
30 {
31 if (!Array.isArray(keys))
kzar 2016/12/12 14:17:50 If it's possible that keys isn't an array then wou
Oleksandr 2016/12/13 06:21:19 Fair enough. Removed this check.
kzar 2016/12/13 10:24:04 Well are you sure that keys will always be an Arra
32 {
33 callback(values[0]);
34 return;
35 }
36 var items = {};
37 keys.forEach(function(key, idx)
kzar 2016/12/12 14:17:50 Would be clearer like this: for (let i = 0; i < k
Oleksandr 2016/12/13 06:21:19 Done. I thought functional way was less C++'y :)
kzar 2016/12/13 10:24:04 Thanks. (It's not functional to iteratively mutate
38 {
39 if (values[idx] != null)
40 items[key] = values[idx];
41 });
42 callback(items);
43 }).catch(function(err)
44 {
45 callback(null);
46 });
47 },
48 set: function(key, value, callback)
49 {
50 localforage.getItem(key).then(function(oldValue)
51 {
52 localforage.setItem(key, value, callback);
kzar 2016/12/12 14:17:50 Shouldn't we wait until setItem finishes before di
Oleksandr 2016/12/13 06:21:19 Done.
53
54 var changes = {};
55 var change = changes[key] = {};
56 change.oldValue = oldValue;
57 change.newValue = value;
58
59 ext.storage.onChanged._dispatch(changes);
60 }).catch(function(err)
61 {
62 localforage.setItem(key, value, callback);
kzar 2016/12/12 14:17:50 Seems ugly how this nearly identical logic is dupl
Oleksandr 2016/12/13 06:21:19 Done.
63
64 var changes = {};
65 var change = changes[key] = {};
66 change.oldValue = null;
67 change.newValue = value;
68
69 ext.storage.onChanged._dispatch(changes);
70 });
71 },
72 remove: function(key, callback)
73 {
74 localforage.removeItem(key);
kzar 2016/12/12 14:17:50 What about the callback?
Oleksandr 2016/12/13 06:21:19 Done.
75 },
76 onChanged: new ext._EventTarget()
77 };
78
kzar 2016/12/12 14:17:50 Nit: No need for this blank line.
Oleksandr 2016/12/13 06:21:19 Done.
79 })();
OLDNEW
« README.md ('K') | « README.md ('k') | edge/localforage.min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld