Skip to content

Latest commit

 

History

History
57 lines (37 loc) · 1.8 KB

File metadata and controls

57 lines (37 loc) · 1.8 KB

API reference

createReconciler(options)

Creates an isolated in-memory identity reconciler.

Required option:

  • getId(entity): returns the canonical ID or undefined for a non-canonical value.

Optional options:

  • getMutationId(entity): extracts a client mutation ID echoed by the server.
  • merge(current, incoming, context): merges canonical data. The default returns incoming.
  • createViewKey(mutationId): custom optimistic view-key factory.
  • createCanonicalViewKey(canonicalId): custom server-only view-key factory.

String and number IDs are supported and kept distinct.

Mutation methods

insertOptimistic(entity, { mutationId, viewKey? })

Registers a local create. Mutation IDs and view keys must be unique.

acknowledge(mutationId, { canonicalId, entity? })

Records an explicit receipt. If a canonical observation arrived earlier, its temporary entry is merged into the optimistic entry and removed.

observe(entity, { canonicalId?, mutationId? }?)

Processes a canonical record from any transport. Explicit options override the configured extractors.

reject(mutationId, error?)

Marks an unsettled mutation as failed. It returns undefined for an unknown mutation and leaves synced entries unchanged.

remove(viewKey)

Removes an entry and its mutation/canonical mappings. Returns whether an entry was removed.

Read methods

  • getSnapshot() returns a referentially stable readonly array until a mutation occurs.
  • getByViewKey(viewKey) looks up the stable UI identity.
  • getByMutationId(mutationId) looks up a create attempt.
  • getByCanonicalId(canonicalId) looks up the server identity.
  • canonicalIdFor(mutationId) returns a resolved canonical ID.
  • subscribe(listener) registers an external-store listener and returns an unsubscribe function.