import { Observable } from "@noya-app/observable"; import { Task } from "./tasks"; export class TaskManager { constructor(public options: { maxTasks?: number } = {}) {} tasks$ = new Observable([]); setTasks(tasks: Task[]) { const old = this.tasks$.get(); const newIds = new Set(tasks.map((t) => t.id)); // merge old and new tasks, preferring new tasks const unchanged = old.filter((t) => !newIds.has(t.id)); const merged = [...unchanged, ...tasks]; this.tasks$.set(merged.slice(0, this.options.maxTasks ?? 20)); } getTasks() { return this.tasks$.get(); } }