Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
josephrocca authored Apr 9, 2023
1 parent cae5894 commit 5615438
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3587,11 +3587,17 @@
// https://stackoverflow.com/a/58983264/11950764
// This tracks all changes to the object, including nested objects, and including new objects/arrays that are added as properties.
let deepOnChangeProxyCache = new WeakMap();
function createDeepOnChangeProxy(target, onChange) {
return new Proxy(target, {
get(target, property) {
const item = target[property];
if (item && typeof item === 'object') return createDeepOnChangeProxy(item, onChange);
if (item && typeof item === 'object') {
if (deepOnChangeProxyCache.has(item)) return deepOnChangeProxyCache.get(item);
const proxy = createDeepOnChangeProxy(item, onChange);
deepOnChangeProxyCache.set(item, proxy);
return proxy;
}
return item;
},
set(target, property, newValue) {
Expand Down

0 comments on commit 5615438

Please sign in to comment.