{"ScriptPreparationCode":"// Initial state\r\nvar state = {\r\n visible: false,\r\n lazy: { test: true, number: 44 },\r\n count: 1\r\n}\r\n\r\n// Define reducers ahead of time\r\n\r\nvar spread = state =\u003E ({\r\n ...state,\r\n lazy: {\r\n ...state.lazy,\r\n test: !state.lazy.test\r\n }\r\n})\r\n\r\n\r\nvar lens = R.lensPath([\u0022lazy\u0022, \u0022test\u0022])\r\nvar ramda = state =\u003E {\r\n return R.over(lens, test =\u003E !test, state)\r\n}\r\n\r\nvar iuUpdate = state =\u003E iu(state, \u0022lazy/test\u0022, !state.lazy.test)\r\n\r\n\r\nfunction iu(state, subArray, val) {\r\n if (!subArray) {\r\n console.log(\u0022No target provided\u0022)\r\n } else if (subArray.length \u003C 1) {\r\n console.log(\u0022No target provided\u0022)\r\n } else if (!state) {\r\n console.log(\u0022No state object provided\u0022)\r\n } else {\r\n if (typeof subArray === \u0022string\u0022) {\r\n subArray = subArray.split(\u0022/\u0022).filter(segment =\u003E segment)\r\n }\r\n return reducer(state, subArray, cloner(val), 0)\r\n }\r\n}\r\n\r\nfunction reducer(_state, subArray, val, l) {\r\n try {\r\n const key = subArray[l]\r\n if (l \u002B 1 === subArray.length) {\r\n const replacer = isEmpty(val) ? undefined : val\r\n return replacer !== undefined\r\n ? Object.assign({}, _state, { [key]: replacer })\r\n : stateWithoutKey(_state, key)\r\n } else {\r\n const value = !isEmpty(_state[key]) ? _state[key] : {}\r\n return Object.assign({}, _state, {\r\n [key]: reducer(value, subArray, val, l \u002B 1),\r\n })\r\n }\r\n } catch (error) {\r\n console.log(\u0022reducer error =\u003E\u0022, error)\r\n }\r\n}\r\n\r\nfunction cloner(arg) {\r\n try {\r\n return JSON.parse(JSON.stringify(arg))\r\n } catch (e) {\r\n return null\r\n }\r\n}\r\n\r\nfunction isEmpty(val) {\r\n return (\r\n val === undefined ||\r\n val === null ||\r\n (typeof val === \u0022object\u0022 \u0026\u0026 Array.isArray(val) \u0026\u0026 val.length === 0) ||\r\n (typeof val === \u0022object\u0022 \u0026\u0026\r\n !Array.isArray(val) \u0026\u0026\r\n Object.keys(val).length === 0)\r\n )\r\n}\r\n\r\nfunction stateWithoutKey(state, key) {\r\n const { [key]: value, ...withoutKey } = state\r\n return withoutKey\r\n}\r\n","TestCases":[{"Name":"Spread","Code":"var data = spread(state)","IsDeferred":false},{"Name":"Ramda lens","Code":"var data = ramda(state)","IsDeferred":false},{"Name":"IU","Code":"var data = iuUpdate(state)","IsDeferred":false}]}