15 lines
630 B
TypeScript
15 lines
630 B
TypeScript
|
|
// 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.
|
||
|
|
export 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 };
|
||
|
|
}
|