Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
fix: chunked update callback
Browse files Browse the repository at this point in the history
  • Loading branch information
hibig committed Aug 23, 2023
1 parent 8798b8a commit 4810199
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/views/commons/hooks/use-update-chunked-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,27 @@ export function useUpdateChunkedList(
// CREATE
if (data?.type === websocketEventType.CREATE) {
dataList.value = _.concat(collections, dataList.value);
return;
}
// DELETE
if (data?.type === websocketEventType.DELETE) {
dataList.value = _.filter(dataList.value, (item) => {
return !_.find(ids, (id) => id === item.id);
});
return;
}
// UPDATE
_.each(collections, (item) => {
const updateIndex = _.findIndex(
dataList.value,
(sItem) => sItem.id === item.id
);
if (updateIndex > -1) {
const updateItem = _.cloneDeep(item);
dataList.value[updateIndex] = updateItem;
}
});
if (data?.type === websocketEventType.UPDATE) {
_.each(collections, (item) => {
const updateIndex = _.findIndex(
dataList.value,
(sItem) => sItem.id === item.id
);
if (updateIndex > -1) {
const updateItem = _.cloneDeep(item);
dataList.value[updateIndex] = updateItem;
}
});
}

if (options?.callback) {
options?.callback(dataList.value);
}
Expand Down

0 comments on commit 4810199

Please sign in to comment.