Commit ea22495e authored by Martin Fahl's avatar Martin Fahl

removes code for debouncing

parent 28eaaded
const debounced = (delay, fn) => {
let timerId;
return function (...args) {
if (timerId) {
clearTimeout(timerId)
}
timerId = setTimeout(() => {
fn(...args)
timerId = null
}, delay)
}
}
export default debounced
\ No newline at end of file
import * as types from "../constants/ActionTypes"
import Axios from "axios"
import debounced from "./debounced"
export const itemAdded = (id, name, quantity) => ({
type: types.ITEM_ADDED,
......@@ -38,15 +37,7 @@ export const deleteItem = (id) => dispatch => {
return Axios.delete("/api/items/"+id).then(dispatch(itemDeleted(id)))
}
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))
debouncedPUT(dispatch, id, name, quantity)
Axios.put("/api/items/"+id, {id, name, quantity}).catch(dispatch(getAllItems))
}
\ 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