Commit fa426a4a authored by Martin Fahl's avatar Martin Fahl

adds debouncing

parent 31ce42a8
......@@ -89,6 +89,18 @@ export const deleteItem = (id) => dispatch => {
export const updateItem = (id, name, quantity) => dispatch => {
dispatch(itemUpdated(id, name, quantity))
Axios.put('/api/items/'+id, {id, name, quantity}).catch(dispatch(getAllItems));
debounced(500, Axios.put('/api/items/'+id, {id, name, quantity}).catch(dispatch(getAllItems)))
}
const debounced = (delay, fn) => {
let timerId;
return function (...args) {
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(() => {
fn(...args);
timerId = null;
}, delay);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment