Skip to content

Commit

Permalink
fix(pagination): remove update event from afterUpdate cycle
Browse files Browse the repository at this point in the history
It should only be called when page, pageSize values change after mounting.
metonym committed Sep 14, 2020
1 parent 0138910 commit 458d1b5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Pagination/Pagination.svelte
Original file line number Diff line number Diff line change
@@ -91,18 +91,14 @@
*/
export let id = "ccs-" + Math.random().toString(36);
import { afterUpdate, createEventDispatcher } from "svelte";
import { createEventDispatcher } from "svelte";
import CaretLeft16 from "carbon-icons-svelte/lib/CaretLeft16";
import CaretRight16 from "carbon-icons-svelte/lib/CaretRight16";
import { Button } from "../Button";
import { Select, SelectItem } from "../Select";
const dispatch = createEventDispatcher();
afterUpdate(() => {
dispatch("update", { pageSize, page });
});
$: {
if (typeof page !== "number") {
page = Number(page);
@@ -111,6 +107,8 @@
if (typeof pageSize !== "number") {
pageSize = Number(pageSize);
}
dispatch("update", { pageSize, page });
}
$: totalPages = Math.max(Math.ceil(totalItems / pageSize), 1);
$: selectItems = Array.from({ length: totalPages }, (_, i) => i);

0 comments on commit 458d1b5

Please sign in to comment.