( taskId: string, setAppState: SetAppState, updater: (task: T) => T, )
| 46 | * Generic to allow type-safe updates for specific task types. |
| 47 | */ |
| 48 | export function updateTaskState<T extends TaskState>( |
| 49 | taskId: string, |
| 50 | setAppState: SetAppState, |
| 51 | updater: (task: T) => T, |
| 52 | ): void { |
| 53 | setAppState(prev => { |
| 54 | const task = prev.tasks?.[taskId] as T | undefined |
| 55 | if (!task) { |
| 56 | return prev |
| 57 | } |
| 58 | const updated = updater(task) |
| 59 | if (updated === task) { |
| 60 | // Updater returned the same reference (early-return no-op). Skip the |
| 61 | // spread so s.tasks subscribers don't re-render on unchanged state. |
| 62 | return prev |
| 63 | } |
| 64 | return { |
| 65 | ...prev, |
| 66 | tasks: { |
| 67 | ...prev.tasks, |
| 68 | [taskId]: updated, |
| 69 | }, |
| 70 | } |
| 71 | }) |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Register a new task in AppState. |
no test coverage detected