I firmly believe in free software. The application I'm making here have capabilities that I've not seen in any system. It presents itself as an opportunity to collaborate on a tool that serves the people rather than corporations. Whose incentives are to help people rather, not make the most money. And whose terms ensure that these freedoms and incentives cannot be taken back or subverted. I license this software under the AGPL.
18 lines
562 B
TypeScript
18 lines
562 B
TypeScript
/*
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
import type { ApiEntity, ApiTombstone } from "~/shared/types/api";
|
|
|
|
export function applyUpdatesToArray<T extends ApiEntity | ApiTombstone>(updates: T[], entities: T[]) {
|
|
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);
|
|
}
|
|
}
|
|
}
|