2025-06-24 15:19:11 +02:00
|
|
|
import type { ApiEntity, ApiTombstone } from "~/shared/types/api";
|
2025-06-11 21:05:17 +02:00
|
|
|
|
2025-06-24 15:19:11 +02:00
|
|
|
export function applyUpdatesToArray<T extends ApiEntity | ApiTombstone>(updates: T[], entities: T[]) {
|
2025-06-11 21:05:17 +02:00
|
|
|
const idMap = new Map(entities.map((e, i) => [e.id, i]));
|
|
|
|
for (const update of updates) {
|
|
|
|
const index = idMap.get(update.id);
|
|
|
|
if (index !== undefined) {
|
|
|
|
entities[index] = update;
|
|
|
|
} else {
|
|
|
|
idMap.set(update.id, entities.length);
|
|
|
|
entities.push(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|