UNPKG

@tanstack/query-core

Version:

The framework agnostic core that powers TanStack Query

1 lines 1.76 kB
{"version":3,"sources":["../../src/removable.ts"],"sourcesContent":["import { timeoutManager } from './timeoutManager'\nimport { environmentManager } from './environmentManager'\nimport { isValidTimeout } from './utils'\nimport type { ManagedTimerId } from './timeoutManager'\n\nexport abstract class Removable {\n gcTime!: number\n #gcTimeout?: ManagedTimerId\n\n destroy(): void {\n this.clearGcTimeout()\n }\n\n protected scheduleGc(): void {\n this.clearGcTimeout()\n\n if (isValidTimeout(this.gcTime)) {\n this.#gcTimeout = timeoutManager.setTimeout(() => {\n this.optionalRemove()\n }, this.gcTime)\n }\n }\n\n protected updateGcTime(newGcTime: number | undefined): void {\n // Default to 5 minutes (Infinity for server-side) if no gcTime is set\n this.gcTime = Math.max(\n this.gcTime || 0,\n newGcTime ?? (environmentManager.isServer() ? Infinity : 5 * 60 * 1000),\n )\n }\n\n protected clearGcTimeout() {\n if (this.#gcTimeout) {\n timeoutManager.clearTimeout(this.#gcTimeout)\n this.#gcTimeout = undefined\n }\n }\n\n protected abstract optionalRemove(): void\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,gCAAmC;AACnC,mBAA+B;AAF/B;AAKO,IAAe,YAAf,MAAyB;AAAA,EAAzB;AAEL;AAAA;AAAA,EAEA,UAAgB;AACd,SAAK,eAAe;AAAA,EACtB;AAAA,EAEU,aAAmB;AAC3B,SAAK,eAAe;AAEpB,YAAI,6BAAe,KAAK,MAAM,GAAG;AAC/B,yBAAK,YAAa,qCAAe,WAAW,MAAM;AAChD,aAAK,eAAe;AAAA,MACtB,GAAG,KAAK,MAAM;AAAA,IAChB;AAAA,EACF;AAAA,EAEU,aAAa,WAAqC;AAE1D,SAAK,SAAS,KAAK;AAAA,MACjB,KAAK,UAAU;AAAA,MACf,cAAc,6CAAmB,SAAS,IAAI,WAAW,IAAI,KAAK;AAAA,IACpE;AAAA,EACF;AAAA,EAEU,iBAAiB;AACzB,QAAI,mBAAK,aAAY;AACnB,2CAAe,aAAa,mBAAK,WAAU;AAC3C,yBAAK,YAAa;AAAA,IACpB;AAAA,EACF;AAGF;AAhCE;","names":[]}