Skip to content

Commit 5d75fe2

Browse files
KATO-Hiroclaude
andcommitted
fix: Replace $derived(() => ...) with $derived.by() in TaskTable
- taskResultsMap and taskIndicesMap: $derived(() => fn) held a function ref instead of computing a value; $derived.by() evaluates the factory correctly - Revert SvelteMap to plain Map in reduce accumulator ($derived tracks reactivity) - Remove call-site () invocations now that derived values are accessed directly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 84aa1a8 commit 5d75fe2

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/features/tasks/components/contest-table/TaskTable.svelte

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@
146146
147147
// Update task results dynamically.
148148
// Computational complexity of preparation table: O(N), where N is the number of task results.
149-
let taskResultsMap = $derived(() => {
149+
let taskResultsMap = $derived.by(() => {
150150
return taskResults.reduce(
151-
(map: SvelteMap<ContestTaskPairKey, TaskResult>, taskResult: TaskResult) => {
151+
(map: Map<ContestTaskPairKey, TaskResult>, taskResult: TaskResult) => {
152152
const key = createContestTaskPairKey(taskResult.contest_id, taskResult.task_id);
153153
154154
if (!map.has(key)) {
@@ -161,7 +161,7 @@
161161
);
162162
});
163163
164-
let taskIndicesMap = $derived(() => {
164+
let taskIndicesMap = $derived.by(() => {
165165
const indices = new Map<ContestTaskPairKey, number>();
166166
167167
taskResults.forEach((task, index) => {
@@ -174,13 +174,12 @@
174174
175175
function handleUpdateTaskResult(updatedTask: TaskResult): void {
176176
const key = createContestTaskPairKey(updatedTask.contest_id, updatedTask.task_id);
177-
const map = taskResultsMap();
178177
179-
if (map.has(key)) {
180-
map.set(key, updatedTask);
178+
if (taskResultsMap.has(key)) {
179+
taskResultsMap.set(key, updatedTask);
181180
}
182181
183-
const index = taskIndicesMap().get(key);
182+
const index = taskIndicesMap.get(key);
184183
185184
if (index !== undefined) {
186185
const newTaskResults = [...taskResults];

0 commit comments

Comments
 (0)