From 5615438d4606b1af4ff6372748796a1b52ffd62b Mon Sep 17 00:00:00 2001 From: josephrocca <1167575+josephrocca@users.noreply.github.com> Date: Sun, 9 Apr 2023 14:18:08 +0800 Subject: [PATCH] Update index.html --- index.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index a7271a3..ced7b09 100644 --- a/index.html +++ b/index.html @@ -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) {