mirror of
https://github.com/wukko/cobalt.git
synced 2025-06-12 05:07:41 +02:00
web/state/task-manager: use writable-readonly store instead of readable
This commit is contained in:
@ -1,38 +1,32 @@
|
|||||||
import { readable, type Updater } from "svelte/store";
|
import { readonly, writable } from "svelte/store";
|
||||||
|
|
||||||
import type { CobaltWorkerProgress } from "$lib/types/workers";
|
import type { CobaltWorkerProgress } from "$lib/types/workers";
|
||||||
import type { CobaltCurrentTasks, CobaltCurrentTaskItem } from "$lib/types/task-manager";
|
import type { CobaltCurrentTasks, CobaltCurrentTaskItem } from "$lib/types/task-manager";
|
||||||
|
|
||||||
let update: (_: Updater<CobaltCurrentTasks>) => void;
|
const currentTasks_ = writable<CobaltCurrentTasks>({});
|
||||||
|
export const currentTasks = readonly(currentTasks_);
|
||||||
export const currentTasks = readable<CobaltCurrentTasks>(
|
|
||||||
{},
|
|
||||||
(_, _update) => { update = _update }
|
|
||||||
);
|
|
||||||
|
|
||||||
export function addWorkerToQueue(workerId: string, item: CobaltCurrentTaskItem) {
|
export function addWorkerToQueue(workerId: string, item: CobaltCurrentTaskItem) {
|
||||||
update(tasks => {
|
currentTasks_.update(tasks => {
|
||||||
tasks[workerId] = item;
|
tasks[workerId] = item;
|
||||||
return tasks;
|
return tasks;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeWorkerFromQueue(id: string) {
|
export function removeWorkerFromQueue(id: string) {
|
||||||
update(tasks => {
|
currentTasks_.update(tasks => {
|
||||||
delete tasks[id];
|
delete tasks[id];
|
||||||
return tasks;
|
return tasks;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateWorkerProgress(workerId: string, progress: CobaltWorkerProgress) {
|
export function updateWorkerProgress(workerId: string, progress: CobaltWorkerProgress) {
|
||||||
update(allTasks => {
|
currentTasks_.update(allTasks => {
|
||||||
allTasks[workerId].progress = progress;
|
allTasks[workerId].progress = progress;
|
||||||
return allTasks;
|
return allTasks;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearCurrentTasks() {
|
export function clearCurrentTasks() {
|
||||||
update(() => {
|
currentTasks_.set({});
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user