1
0
Fork 0
This commit is contained in:
Chocobozzz 2020-05-22 08:50:31 +02:00
parent f33dc6ab2d
commit fd8f73cf6d
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 21 additions and 21 deletions

View File

@ -2,6 +2,27 @@
const valuesMap = new Map()
function proxify (instance: MemoryStorage) {
return new Proxy(instance, {
set: function (obj, prop: string | number, value) {
if (MemoryStorage.prototype.hasOwnProperty(prop)) {
instance[prop] = value
} else {
instance.setItem(prop, value)
}
return true
},
get: function (target, name: string | number) {
if (MemoryStorage.prototype.hasOwnProperty(name)) {
return instance[name]
}
if (valuesMap.has(name)) {
return instance.getItem(name)
}
}
})
}
class MemoryStorage {
[key: string]: any
[index: number]: string
@ -50,27 +71,6 @@ try {
const instanceLocalStorage = new MemoryStorage()
const instanceSessionStorage = new MemoryStorage()
function proxify (instance: MemoryStorage) {
return new Proxy(instance, {
set: function (obj, prop: string | number, value) {
if (MemoryStorage.prototype.hasOwnProperty(prop)) {
instance[prop] = value
} else {
instance.setItem(prop, value)
}
return true
},
get: function (target, name: string | number) {
if (MemoryStorage.prototype.hasOwnProperty(name)) {
return instance[name]
}
if (valuesMap.has(name)) {
return instance.getItem(name)
}
}
})
}
peertubeLocalStorage = proxify(instanceLocalStorage)
peertubeSessionStorage = proxify(instanceSessionStorage)
}