{"ScriptPreparationCode":"\r\nfunction proxy(initialState) {\r\n if (!(typeof initialState === \u0022object\u0022 \u0026\u0026 initialState !== null) \u0026\u0026 Array.isArray(initialState)) {\r\n throw new Error(\u0022proxy must be an object or an array\u0022);\r\n }\r\n\r\n const handler = {\r\n get(target, property) {\r\n return target[property];\r\n },\r\n\r\n set(target, property, value) {\r\n // Short-circuit if value changed is the same, prevents performance issues.\r\n if (target[property] === value) return true;\r\n\r\n // initialised ?? customLog(target, property, value);\r\n console.log(target, property, value);\r\n\r\n if (typeof value === \u0022object\u0022) {\r\n value = proxy(value);\r\n }\r\n\r\n return target[property] = value;\r\n \r\n },\r\n };\r\n\r\n const proxiedObject = new Proxy({}, handler);\r\n\r\n /**\r\n * We need to loop the state manually inorder to convert the deeply nested\r\n * objects into proxies.\r\n *\r\n * Initially the proxied object is {} empty.\r\n * When we loop, we take every key from the initialState passed as parameter and set it in the proxiedObject along with it\u0027s value. When this is done, the set() TRAP is called internally. During which we check if the initalState\u0027s value is an array or object. If so, we wrap it in another Proxy and set it as the value to the parent proxiedObject.\r\n */\r\n for (const key in initialState) {\r\n proxiedObject[key] = initialState[key];\r\n }\r\n\r\n initialised = true;\r\n\r\n return proxiedObject;\r\n}","TestCases":[{"Name":"Object GET","Code":"const testObj = {a:1,b:2,c:[1,2,3],d:{e:1000}};\r\ntestObj.a;\r\ntestObj.d.e;\r\ntestObj.c[2];","IsDeferred":false},{"Name":"Proxy GET","Code":"const testObj = proxy({a:1,b:2,c:[1,2,3],d:{e:1000}});\r\ntestObj.a;\r\ntestObj.d.e;\r\ntestObj.c[2];","IsDeferred":false},{"Name":"Simple Proxy GET","Code":"const testObj = proxy({a:1})\r\ntestObj.a;","IsDeferred":false},{"Name":"Simple Proxy SET","Code":"const testObj = proxy({a:1})\r\ntestObj.a = 100;\r\ntestObj.a","IsDeferred":false},{"Name":"Complex Proxy SET","Code":"const testObj = proxy({a:1,b:2,c:[1,2,3],d:{e:1000}});\r\ntestObj.a;\r\ntestObj.d.e = \u0027meow\u0027;\r\ntestObj.c[2] = \u0027apple\u0027;","IsDeferred":false}]}