Files
kochwas/src/lib/sw/diff-manifest.ts

15 lines
623 B
TypeScript
Raw Normal View History

// Vergleicht die aktuelle Rezept-ID-Liste (vom Server) mit dem, was
// der Cache schon hat. Der SW nutzt das Delta, um nur Neue zu laden
// und Gelöschte abzuräumen.
type ManifestDiff = { toAdd: number[]; toRemove: number[] };
export function diffManifest(currentIds: number[], cachedIds: number[]): ManifestDiff {
const current = new Set(currentIds);
const cached = new Set(cachedIds);
const toAdd: number[] = [];
const toRemove: number[] = [];
for (const id of current) if (!cached.has(id)) toAdd.push(id);
for (const id of cached) if (!current.has(id)) toRemove.push(id);
return { toAdd, toRemove };
}