UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

52 lines (51 loc) 1.72 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const irStableIdentity = require("./ir-stable-identity.cjs"); class DeduplicatedLoadSubset { constructor(options) { this.options = options; this.completed = /* @__PURE__ */ new Set(); this.inflight = /* @__PURE__ */ new Map(); this.generation = 0; this.loadSubset = (options2) => { const key = irStableIdentity.getLoadSubsetDemandKey(options2); if (this.completed.has(key)) { this.options.onDeduplicate?.(options2); return true; } const existing = options2.signal ? void 0 : this.inflight.get(key); if (existing) { void 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.inflight.get(key) === promise) this.inflight.delete(key); }); if (!options2.signal && generation === this.generation) { this.inflight.set(key, promise); } return promise; }; } reset() { this.completed.clear(); this.inflight.clear(); this.generation++; } } exports.DeduplicatedLoadSubset = DeduplicatedLoadSubset; //# sourceMappingURL=subset-dedupe.cjs.map