Last active
May 14, 2022 10:35
-
-
Save refracta/a732045ddb96efb6dbf353d05aacfed8 to your computer and use it in GitHub Desktop.
Object Proxy of localStorage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ls = new Proxy(localStorage, { | |
get: (o1, p1) => o1[p1] ? new Proxy(JSON.parse(o1[p1]), { | |
get: (o2, p2) => typeof o2[p2] === 'function' ? function () { let r = o2[p2].apply(o2, arguments); ls[p1] = o2; return r; } : o2[p2], | |
set: (o2, p2, v2) => { o2[p2] = v2; ls[p1] = o2 } | |
}) : null, | |
set: (o, p, v) => o[p] = JSON.stringify(v) | |
}); | |
/* | |
let ls = new Proxy(localStorage, | |
{ | |
get: (o, p) => { | |
let level = 1; | |
let map = {['o' + level]: o, ['p' + level]: p}; | |
function recur(o, p) { | |
} | |
recur(o, p); | |
} | |
set: (o, p, v) => o[p] = JSON.stringify(v) | |
} | |
); | |
*/ | |
// Primitive number , string , boolean , null , undefined , symbol, bigint | |
// Only depth 1 | |
// TODO: depth N |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment