КС
с соответствующими id
Size: a a a
КС
R
R
R
A
КС
A
КС
КС
R
R
AK
$: objectsById = currentObjects.reduce((items, item) => {
items[item.id] = item;
return items;
}, {});
function onEvent(newObjects) {
let objectsToReplace = {};
let objectsToAdd = [];
for (const obj of newObjects) {
if (items[obj.id]) {
objectsToReplace[obj.id] = obj;
} else {
objectsToAdd.push(obj);
}
}
const newObjects = currentObjects.map((obj) => {
return objectsToReplace[obj.id]
? objectsToReplace[obj.id]
: obj;
});
newObjects.push(objectsToAdd);
currentObjects = newObjects;
}
{#each expression as name (key)}...{/each}
R
R
R
R
R
КС
AK
{#each expression as name (key)}...{/each}
R