Skip to content
Snippets Groups Projects
Commit f2da91c5 authored by DD Liu's avatar DD Liu
Browse files

throttle requests and fix code for merging new and old state

parent 386c3968
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,22 @@ const reducer = function (state, action) { ...@@ -7,7 +7,22 @@ const reducer = function (state, action) {
switch (action.type) { switch (action.type) {
// Adds or updates monitors // Adds or updates monitors
case UPDATE_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: default:
return state; return state;
} }
...@@ -18,7 +33,7 @@ reducer.updateMonitors = function (monitors) { ...@@ -18,7 +33,7 @@ reducer.updateMonitors = function (monitors) {
type: UPDATE_MONITORS, type: UPDATE_MONITORS,
monitors: monitors, monitors: monitors,
meta: { meta: {
throttle: 30 throttle: 100
} }
}; };
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment