UNPKG

@tanstack/query-core

Version:

The framework agnostic core that powers TanStack Query

1 lines 1.76 kB
{"version":3,"file":"removable.cjs","names":["isValidTimeout","timeoutManager","isServerEnvironment"],"sources":["../../src/removable.ts"],"sourcesContent":["import { timeoutManager } from './timeoutManager'\nimport { isServer as isServerEnvironment } 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 ?? (isServerEnvironment() ? Infinity : 5 * 60 * 1000),\n )\n }\n\n protected clearGcTimeout() {\n if (this.#gcTimeout !== undefined) {\n timeoutManager.clearTimeout(this.#gcTimeout)\n this.#gcTimeout = undefined\n }\n }\n\n protected abstract optionalRemove(): void\n}\n"],"mappings":";;;;;;;AAKA,IAAsB,YAAtB,MAAgC;;;;CAI9B,UAAgB;EACd,KAAK,eAAe;CACtB;CAEA,aAA6B;EAC3B,KAAK,eAAe;EAEpB,IAAIA,cAAAA,eAAe,KAAK,MAAM,GAC5B,8BAAA,uBAAA,YAAA,MAAkBC,uBAAAA,eAAe,iBAAiB;GAChD,KAAK,eAAe;EACtB,GAAG,KAAK,MAAM,CAAA;CAElB;CAEA,aAAuB,WAAqC;EAE1D,KAAK,SAAS,KAAK,IACjB,KAAK,UAAU,GACf,cAAcC,2BAAAA,SAAoB,IAAI,WAAW,IACnD;CACF;CAEA,iBAA2B;EACzB,IAAA,8BAAA,uBAAA,YAAI,IAAA,MAAoB,KAAA,GAAW;GACjC,uBAAA,eAAe,aAAA,8BAAA,uBAAA,YAAa,IAAA,CAAe;GAC3C,8BAAA,uBAAA,YAAA,MAAkB,KAAA,CAAA;EACpB;CACF;AAGF"}