Commit d52e8dc2 authored by Martin Fahl's avatar Martin Fahl

fixes debouncing for multiple items incremented

parent 88a15d89
......@@ -38,7 +38,13 @@ export const deleteItem = (id) => dispatch => {
return Axios.delete("/api/items/"+id).then(dispatch(itemDeleted(id)))
}
const debouncedPUT = debounced(500, (dispatch, id, name, quantity) => Axios.put("/api/items/"+id, {id, name, quantity}).catch(dispatch(getAllItems)))
const debouncedPUTMap = new Map()
const debouncedPUT = (dispatch, id, name, quantity) => {
if (!debouncedPUTMap.has(id)) {
debouncedPUTMap.set(id, debounced(2000, (dispatch, id, name, quantity) => Axios.put("/api/items/"+id, {id, name, quantity}).catch(dispatch(getAllItems))))
}
debouncedPUTMap.get(id)(dispatch, id, name, quantity)
}
export const updateItem = (id, name, quantity) => dispatch => {
dispatch(itemUpdated(id, name, quantity))
......
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