UNPKG

@rpldy/uploader

Version:

the processing and queuing engine for react-uploady

27 lines 912 B
import { ITEM_FINALIZE_STATES } from "../consts"; const finalizeItem = (queue, id, delItem = false) => { queue.updateState(state => { const { batchId } = state.items[id] || { batchId: null }; if (delItem) { delete state.items[id]; } const index = batchId ? state.itemQueue[batchId].indexOf(id) : -1; if (~index && batchId) { state.itemQueue[batchId].splice(index, 1); } const activeIndex = state.activeIds.indexOf(id); if (~activeIndex) { state.activeIds.splice(activeIndex, 1); } if (batchId && state.batches[batchId].itemBatchOptions[id]) { delete state.batches[batchId].itemBatchOptions[id]; } }); }; const getIsItemExists = (queue, itemId) => !!queue.getState().items[itemId]; const getIsItemFinalized = item => ITEM_FINALIZE_STATES.includes(item.state); export { finalizeItem, getIsItemExists, getIsItemFinalized };