perf: don't interate through all of localStorage in inline script (#1264)
This commit is contained in:
parent
58a8772edc
commit
5d0e95e759
|
@ -8,19 +8,13 @@ const hasLocalStorage = testHasLocalStorageOnce()
|
||||||
|
|
||||||
export const storeLite = {
|
export const storeLite = {
|
||||||
get () {
|
get () {
|
||||||
if (!hasLocalStorage) {
|
return new Proxy({}, {
|
||||||
return {}
|
get: function (obj, prop) {
|
||||||
|
if (!(prop in obj)) {
|
||||||
|
obj[prop] = hasLocalStorage && safeParse(localStorage.getItem(`store_${prop}`))
|
||||||
}
|
}
|
||||||
const res = {}
|
return obj[prop]
|
||||||
const LS = localStorage
|
}
|
||||||
for (let i = 0, len = LS.length; i < len; i++) {
|
})
|
||||||
let key = LS.key(i)
|
|
||||||
if (key.startsWith('store_')) {
|
|
||||||
let item = LS.getItem(key)
|
|
||||||
let value = safeParse(item)
|
|
||||||
res[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue