UNPKG

violet-paginator

Version:

Display, paginate, sort, filter, and update items from the server. violet-paginator is a complete list management library for react/redux applications.

25 lines (20 loc) 605 B
import composables from '../actions/simpleComposables' const map = {} export default function updateSemaphore(listId, dispatch) { const mapSlice = map[listId] = map[listId] || {} const actions = composables(listId) return { update: (id, promise) => { mapSlice[id] = mapSlice[id] || 0 dispatch(actions.updatingItem(id)) mapSlice[id]++ return promise.then(resp => { dispatch(actions.updateComplete(id, --mapSlice[id])) return resp }).catch(err => { dispatch(actions.updateFailed(id, --mapSlice[id])) throw err }) } } }