Skip to content

Commit

Permalink
made changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GavriliukArtem committed Aug 8, 2023
1 parent d7c453c commit 17132fd
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@
* @param {Object[]} actions
*/
function transformState(state, action) {
const CLEAR = 'clear';

for (const obj of action) {
// to iterate all objects in array.
for (const [key, value] of Object.entries(obj)) {
// to iterate every object and split on keys and values.
//
// conditions check
if (obj[key] === obj.type && value === 'clear') {
if (obj[key] === obj.type && value === CLEAR) {
for (const ke of Object.keys(state)) {
delete state[ke];
}
}

if (obj[key] === obj.extraData) {
// add key and value to the object
for (const [k, v] of Object.entries(obj[key])) {
state[k] = v;
}
Object.assign(state, obj.extraData);
}

if (obj[key] === obj.keysToRemove) {
// delete properies
for (const k of obj[key]) {
delete state[k];
}
Expand Down

0 comments on commit 17132fd

Please sign in to comment.