diff --git a/src/reducers/monitors.js b/src/reducers/monitors.js index 46cbb2c759776b8fc8cea59f68d79f03e79df717..0e9832fcd7aac36dc3390caf9cf2b0befd0e1659 100644 --- a/src/reducers/monitors.js +++ b/src/reducers/monitors.js @@ -7,7 +7,22 @@ const reducer = function (state, action) { switch (action.type) { // Adds or updates monitors case UPDATE_MONITORS: - return [...action.monitors, ...state]; + let newState = [...state]; + let updated = false; + for (let i = 0; i < action.monitors.length; i++) { + for (let j = 0; j < state.length; j++) { + if (action.monitors[i].id == state[j].id) { + newState[j] = action.monitors[i]; + updated = true; + continue; + } + } + if (!updated) { + newState.push(action.monitors[i]); + } + updated = false; + } + return newState; default: return state; } @@ -18,7 +33,7 @@ reducer.updateMonitors = function (monitors) { type: UPDATE_MONITORS, monitors: monitors, meta: { - throttle: 30 + throttle: 100 } }; };