Skip to content

Commit

Permalink
Ensure row access doesn't mutate state, see: sveltejs/svelte#12457
Browse files Browse the repository at this point in the history
  • Loading branch information
pheuter committed Jul 16, 2024
1 parent 6d1437c commit 94f0694
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-squids-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@careswitch/svelte-data-table': patch
---

Ensure row access doesn't mutate state, see: https://github.com/sveltejs/svelte/issues/12457
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/lib/DataTable.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ export class DataTable<T> {
#globalFilter = $state<string>('');
#globalFilterRegex = $state<RegExp | null>(null);

#isFilterDirty = $state(true);
#isSortDirty = $state(true);

#isFilterDirty = true;
#isSortDirty = true;
#filteredData: T[] = [];
#sortedData: T[] = [];

Expand Down Expand Up @@ -165,6 +164,11 @@ export class DataTable<T> {
* @returns {T[]} An array of rows for the current page.
*/
get rows() {
// React to changes in filter state and sort state
this.#filterState;
this.#sortState;
this.#globalFilterRegex;

this.#applyFilters();
this.#applySort();
const startIndex = (this.currentPage - 1) * this.#pageSize;
Expand Down

0 comments on commit 94f0694

Please sign in to comment.