Skip to content

Commit

Permalink
fix: execute change listeners from reactions with delay
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Mar 8, 2022
1 parent 8606def commit 441f4f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/internalState/cleanupState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export function cleanupState<T>(state: Store<InternalTableState<T>>): void {
const newSort = draft.sort.filter((s) => activeColumnIds.has(s.columnId));
if (newSort.length < draft.sort.length) {
draft.sort = newSort;
draft.props.onSortChange?.(newSort);
setTimeout(() => {
draft.props.onSortChange?.(newSort);
});
}

// Remove filters for non active columns
Expand Down Expand Up @@ -49,14 +51,18 @@ export function cleanupState<T>(state: Store<InternalTableState<T>>): void {
const newSelection = intersect(draft.selection, activeItemsById);
if (newSelection.size !== draft.selection.size) {
draft.selection = newSelection;
draft.props.onSelectionChange?.(newSelection);
setTimeout(() => {
draft.props.onSelectionChange?.(newSelection);
});
}

// Remove expanded for non existing items
const newExpanded = intersect(draft.expanded, itemsById);
if (newExpanded.size < draft.expanded.size) {
draft.expanded = newExpanded;
draft.props.onExpandedChange?.(newExpanded);
setTimeout(() => {
draft.props.onExpandedChange?.(newExpanded);
});
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion src/internalState/syncSelections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export function syncSelections<T>(state: Store<InternalTableState<T>>): void {

if (newSelection.size !== selection.size) {
state.selection = newSelection;
state.props.onSelectionChange?.(newSelection);
setTimeout(() => {
state.props.onSelectionChange?.(newSelection);
});
}
},
{ runNow: true },
Expand Down

0 comments on commit 441f4f4

Please sign in to comment.