@mantlebee/ts-data
    Preparing search index...

    Function withBatching

    • Coalesces the resolve calls made in the same microtask into one call of the inner source with the distinct values, so the fifty cells of a grid page, each resolving its own key without knowing of the others, cost one request instead of fifty. Each caller receives the items of its own values, picked from the shared result with valueOf; a value the inner source does not return is missing for every caller that asked for it; a rejected call of the inner source rejects every caller of the batch. search and valueOf are untouched.

      Signal. The call of the inner source runs without a signal: one caller's abort must not starve the others. The aborted caller alone rejects with AbortedException, at once.

      Matching. A caller gets the items whose valueOf is === to one of its values: a source matching keys loosely (the in-memory one compares strings case-insensitively by default) may return an item no caller recognises; keep the keys primitive and exact.

      Type Parameters

      • TItem

        Type of the items.

      • TValue

        Type of the key of an item.

      Parameters

      Returns ILookupSource<TItem, TValue>

      a source with the same contract, batching resolve.

      const departments = withBatching(createLookupSource(readDepartments, { textField: "name", valueField: "id" }));
      // Rendered in the same tick, the cells share one `valueField in [1, 2]` request.
      cell1.show(departments.resolve([1]));
      cell2.show(departments.resolve([2]));
      cell3.show(departments.resolve([1]));