Skip to content

Commit 5ccbbc9

Browse files
committed
♻️ Use $derived instead of $state and run() (#2083)
1 parent 7f6aadf commit 5ccbbc9

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/lib/components/WorkBook/WorkBookForm.svelte

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script lang="ts">
2-
import { run } from 'svelte/legacy';
3-
42
import { Breadcrumb, BreadcrumbItem } from 'svelte-5-ui-lib';
53
64
import HeadingOne from '$lib/components/HeadingOne.svelte';
@@ -42,11 +40,8 @@
4240
4341
const { form, message, errors, enhance } = superFormObject;
4442
45-
let workBookTasksForTable: WorkBookTasksCreate | WorkBookTasksEdit = $state([]);
46-
47-
// HACK: This is a workaround to ensure that the derived state is updated correctly.
48-
run(() => {
49-
workBookTasksForTable = $form.workBookTasks
43+
let workBookTasksForTable: WorkBookTasksCreate | WorkBookTasksEdit = $derived(
44+
$form.workBookTasks
5045
.map((workBookTask: WorkBookTaskCreate | WorkBookTaskEdit) => {
5146
const task = tasksMapByIds.get(workBookTask.taskId);
5247
@@ -65,8 +60,8 @@
6560
.filter(
6661
(item: WorkBookTaskCreate | WorkBookTaskEdit): item is NonNullable<typeof item> =>
6762
item !== null,
68-
);
69-
});
63+
),
64+
);
7065
7166
const truncateClass = 'min-w-[96px] max-w-[120px] sm:max-w-[300px] lg:max-w-[600px] truncate';
7267
const tasks: Tasks = $derived(Array.from(tasksMapByIds.values()));

0 commit comments

Comments
 (0)