diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/src/app/shared/misc/peertube-web-storage.ts | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/client/src/app/shared/misc/peertube-web-storage.ts b/client/src/app/shared/misc/peertube-web-storage.ts index 6a152dd98..0db1301bd 100644 --- a/client/src/app/shared/misc/peertube-web-storage.ts +++ b/client/src/app/shared/misc/peertube-web-storage.ts | |||
@@ -2,6 +2,27 @@ | |||
2 | 2 | ||
3 | const valuesMap = new Map() | 3 | const valuesMap = new Map() |
4 | 4 | ||
5 | function proxify (instance: MemoryStorage) { | ||
6 | return new Proxy(instance, { | ||
7 | set: function (obj, prop: string | number, value) { | ||
8 | if (MemoryStorage.prototype.hasOwnProperty(prop)) { | ||
9 | instance[prop] = value | ||
10 | } else { | ||
11 | instance.setItem(prop, value) | ||
12 | } | ||
13 | return true | ||
14 | }, | ||
15 | get: function (target, name: string | number) { | ||
16 | if (MemoryStorage.prototype.hasOwnProperty(name)) { | ||
17 | return instance[name] | ||
18 | } | ||
19 | if (valuesMap.has(name)) { | ||
20 | return instance.getItem(name) | ||
21 | } | ||
22 | } | ||
23 | }) | ||
24 | } | ||
25 | |||
5 | class MemoryStorage { | 26 | class MemoryStorage { |
6 | [key: string]: any | 27 | [key: string]: any |
7 | [index: number]: string | 28 | [index: number]: string |
@@ -50,27 +71,6 @@ try { | |||
50 | const instanceLocalStorage = new MemoryStorage() | 71 | const instanceLocalStorage = new MemoryStorage() |
51 | const instanceSessionStorage = new MemoryStorage() | 72 | const instanceSessionStorage = new MemoryStorage() |
52 | 73 | ||
53 | function proxify (instance: MemoryStorage) { | ||
54 | return new Proxy(instance, { | ||
55 | set: function (obj, prop: string | number, value) { | ||
56 | if (MemoryStorage.prototype.hasOwnProperty(prop)) { | ||
57 | instance[prop] = value | ||
58 | } else { | ||
59 | instance.setItem(prop, value) | ||
60 | } | ||
61 | return true | ||
62 | }, | ||
63 | get: function (target, name: string | number) { | ||
64 | if (MemoryStorage.prototype.hasOwnProperty(name)) { | ||
65 | return instance[name] | ||
66 | } | ||
67 | if (valuesMap.has(name)) { | ||
68 | return instance.getItem(name) | ||
69 | } | ||
70 | } | ||
71 | }) | ||
72 | } | ||
73 | |||
74 | peertubeLocalStorage = proxify(instanceLocalStorage) | 74 | peertubeLocalStorage = proxify(instanceLocalStorage) |
75 | peertubeSessionStorage = proxify(instanceSessionStorage) | 75 | peertubeSessionStorage = proxify(instanceSessionStorage) |
76 | } | 76 | } |