Left: | ||
Right: |
OLD | NEW |
---|---|
(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 /* | |
21 * Storage redirection to localforage. In Windows 10 Anniversary Update | |
kzar
2016/12/13 10:24:04
The comment looks much more useful now thanks. Cou
| |
22 * Microsoft Edge has a 1Mb limit on the amount of bytes per transaction in | |
23 * storage.local. Also unlimitedStorage permision is not honoured. Which is why | |
24 * we have to use IndexedDB until those issues are fixed in Creators Update. | |
25 * For reference it is supposed to be fixed in Windows 10 build 14986. | |
26 */ | |
27 | |
28 ext.storage = { | |
29 get: function(keys, callback) | |
30 { | |
31 var promisedValues = keys.map(key => | |
32 { | |
33 return localforage.getItem(key); | |
34 }); | |
35 Promise.all(promisedValues).then(values => | |
36 { | |
37 var items = {}; | |
38 for (let i = 0; i < keys.length; i++) | |
39 { | |
40 if (values[i] != null) | |
41 items[keys[i]] = values[i]; | |
42 } | |
43 callback(items); | |
44 }).catch(err => | |
kzar
2016/12/13 10:24:04
The indentation here for the catch is wrong. Also
| |
45 { | |
46 callback(null); | |
47 }); | |
48 }, | |
49 set: function(key, value, callback) | |
50 { | |
51 function internalSet(oldValue) | |
kzar
2016/12/13 10:24:04
Nit: setThenDispatch or setThenCallback or somethi
| |
52 { | |
53 localforage.setItem(key, value).then(() => | |
54 { | |
55 if (callback) | |
56 callback(null); | |
57 var changes = {}; | |
kzar
2016/12/13 10:24:04
Please move the `var changes = {};` line down, so
| |
58 var change = changes[key] = {}; | |
59 change.oldValue = oldValue; | |
60 change.newValue = value; | |
61 | |
62 ext.storage.onChanged._dispatch(changes); | |
63 }).catch((err) => | |
64 { | |
65 if (callback) | |
66 callback(err); | |
67 }); | |
68 }; | |
69 | |
70 localforage.getItem(key).then(oldValue => internalSet(oldValue)) | |
kzar
2016/12/13 10:24:04
No need to wrap internalSet with another function.
| |
71 .catch(err => internalSet(null)); | |
72 }, | |
73 remove: function(key, callback) | |
74 { | |
75 localforage.removeItem(key, callback); | |
kzar
2016/12/13 10:24:04
Why wrap localforage.removeItem at all? How about
| |
76 }, | |
77 onChanged: new ext._EventTarget() | |
78 }; | |
79 })(); | |
OLD | NEW |