summaryrefslogtreecommitdiff
path: root/src/reducers/states.js
blob: a9eb4ce8166c8ba2de5170b01171a77b54eee75f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import {combineReducers} from "redux";
import {ADD_TO_STATES} from "../actions/states";

export const states = combineReducers({
    task: objectStates("task"),
    room: objectStates("room"),
    rack: objectStates("rack"),
    machine: objectStates("machine"),
});

function objectStates(type) {
    return (state = {}, action) => {
        if (action.objectType !== type) {
            return state;
        }

        if (action.type === ADD_TO_STATES) {
            return Object.assign(
                {},
                state,
                {
                    [action.tick]: Object.assign(
                        {},
                        state[action.tick],
                        {[action.object.id]: action.object}
                    )
                }
            );
        }

        return state;
    };
}