From fba04595f16e765fbc0eb54f11a79b3406e2038f Mon Sep 17 00:00:00 2001 From: KatOlista^^! Date: Mon, 31 Jul 2023 00:00:22 +0200 Subject: [PATCH] add solution --- src/transformState.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/transformState.js b/src/transformState.js index 5dc267d7..13108ba8 100644 --- a/src/transformState.js +++ b/src/transformState.js @@ -6,19 +6,34 @@ */ function transformState(state, actions) { for (let i = 0; i < actions.length; i++) { - if (actions[i].type === 'addProperties') { - Object.assign(state, actions[i].extraData); + switch (actions[i].type) { + case 'addProperties': + Object.assign(state, actions[i].extraData); + break; + case 'removeProperties': + for (const action of actions[i].keysToRemove) { + delete state[action]; + }; + break; + case 'clear': + Object.keys(state).forEach(key => delete state[key]); + break; + default: + return state; } + // if (actions[i].type === 'addProperties') { + // Object.assign(state, actions[i].extraData); + // } - if (actions[i].type === 'removeProperties') { - for (const item of actions[i].keysToRemove) { - delete state[item]; - } - } + // if (actions[i].type === 'removeProperties') { + // for (const action of actions[i].keysToRemove) { + // delete state[action]; + // } + // } - if (actions[i].type === 'clear') { - Object.keys(state).forEach(key => delete state[key]); - } + // if (actions[i].type === 'clear') { + // Object.keys(state).forEach(key => delete state[key]); + // } } }