Store Utilities

reconcile

Edit this page

reconcile is designed for diffing data changes in situations where granular updates cannot be applied. This is useful when dealing with immutable data from stores or handling large API responses.

function reconcile<T>(
value: T | Store<T>,
options?: {
key?: string | null;
merge?: boolean;
} = { key: "id" }
): (
state: T extends NotWrappable ? T : Store<T>
) => T extends NotWrappable ? T : Store<T>;

reconcile has a key option that can be used when available to match items. The value accepts either a value of type T or a Store containing values of type T. This represents the data to be reconciled.

The reconcile function helps manage data changes by performing a diffing process, making it particularly handy in scenarios where applying granular updates is challenging or inefficient.

The key and merge options provide flexibility to customize the reconciliation process based on specific needs.

// subscribing to an observable
const unsubscribe = store.subscribe(({ todos }) => (
setState('todos', reconcile(todos)));
);
onCleanup(() => unsubscribe());
Options
OptionTypeDefaultDescription
keystring"id"Specifies the key to be used for matching items during reconciliation
mergebooleanfalseWhen merge is false, referential checks are performed where possible to determine equality, and items that are not referentially equal are replaced. When merge is true, all diffing is pushed to the leaves, effectively morphing the previous data to the new value.
Report an issue with this page