• Creates a function that synchronizes a plain array of items with new entities. Does not require a container model - works with any array of identifiable items.

    Type Parameters

    • T extends Identifiable

      Current item type with an id property

    • D extends Identifiable

      New entity type with an id property

    Parameters

    • params: ResolveItemsParams<T, D>

      Configuration including the items array and callbacks

    Returns ((entities) => void)

    A function that accepts entities and synchronizes the array

      • (entities): void
      • Parameters

        • entities: D[]

        Returns void

    Example

    const currentItems = [{ id: '1', name: 'Item 1' }];
    const syncItems = resolveItemListDeltas({
    items: currentItems,
    onAddItem: (item) => currentItems.push(item),
    onRemoveItem: (id) => {
    const index = currentItems.findIndex(i => i.id === id);
    if (index >= 0) currentItems.splice(index, 1);
    }
    });
    syncItems(newItems);