UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

43 lines (42 loc) • 1.43 kB
import { getLoadSubsetDemandKey } from "./ir-stable-identity.js"; var DeduplicatedLoadSubset = class { constructor(options) { this.options = options; this.completed = /* @__PURE__ */ new Set(); this.ez = /* @__PURE__ */ new Map(); this.generation = 0; this.loadSubset = (options2) => { const key = getLoadSubsetDemandKey(options2); if (!options2.refetch && this.completed.has(key)) { this.options.onDeduplicate?.(options2); return true; } const existing = options2.signal || options2.refetch ? void 0 : this.ez.get(key); if (existing) { existing.then(() => this.options.onDeduplicate?.(options2)).catch(() => {}); return existing; } const generation = this.generation; const result = this.options.loadSubset(options2); if (result === true) { if (generation === this.generation && !options2.signal?.aborted) this.completed.add(key); return true; } const promise = result.then((value) => { if (generation === this.generation && !options2.signal?.aborted) this.completed.add(key); return value; }).finally(() => { if (this.ez.get(key) === promise) this.ez.delete(key); }); if (!options2.signal && generation === this.generation) this.ez.set(key, promise); return promise; }; } reset() { this.completed.clear(); this.ez.clear(); this.generation++; } }; export { DeduplicatedLoadSubset }; //# sourceMappingURL=subset-dedupe.js.map