From bcf119f2c4ac587cc8263db8a9fc0581521fdec7 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Thu, 28 Sep 2017 22:48:38 +0200 Subject: Implement batch state adding Also fixes the 'hidden states' bug. --- src/reducers/states.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/reducers/states.js') diff --git a/src/reducers/states.js b/src/reducers/states.js index d74c924c..81f078af 100644 --- a/src/reducers/states.js +++ b/src/reducers/states.js @@ -1,5 +1,5 @@ import {combineReducers} from "redux"; -import {ADD_TO_STATES} from "../actions/states"; +import {ADD_BATCH_TO_STATES} from "../actions/states"; export const states = combineReducers({ task: objectStates("task"), @@ -14,17 +14,21 @@ function objectStates(type) { return state; } - if (action.type === ADD_TO_STATES) { + if (action.type === ADD_BATCH_TO_STATES) { + const batch = {}; + for (let i in action.objects) { + batch[action.objects[i].tick] = Object.assign( + {}, + state[action.objects[i].tick], + batch[action.objects[i].tick], + {[action.objects[i][action.objectType + "Id"]]: action.objects[i]} + ); + } + return Object.assign( {}, state, - { - [action.tick]: Object.assign( - {}, - state[action.tick], - {[action.object[action.objectType + "Id"]]: action.object} - ) - } + batch ); } -- cgit v1.2.3