@isograph/react-disposable-state 0.0.0-main-a840a70e → 0.0.0-main-c09c9dbf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.turbo/turbo-compile-libs.log +4 -4
  2. package/.turbo/turbo-tsc.log +1 -1
  3. package/dist/{CacheItem.d.ts → CacheItem.d.cts} +1 -1
  4. package/dist/CacheItem.d.cts.map +1 -0
  5. package/dist/CacheItem.d.mts.map +1 -1
  6. package/dist/CacheItem.mjs.map +1 -1
  7. package/dist/{ParentCache.js → ParentCache.cjs} +1 -1
  8. package/dist/{ParentCache.d.ts → ParentCache.d.cts} +2 -3
  9. package/dist/ParentCache.d.cts.map +1 -0
  10. package/dist/ParentCache.d.mts +0 -1
  11. package/dist/ParentCache.d.mts.map +1 -1
  12. package/dist/ParentCache.mjs.map +1 -1
  13. package/dist/{index.js → index.cjs} +10 -10
  14. package/dist/{index.d.ts → index.d.cts} +7 -7
  15. package/dist/{useCachedResponsivePrecommitValue.js → useCachedResponsivePrecommitValue.cjs} +2 -2
  16. package/dist/{useCachedResponsivePrecommitValue.d.ts → useCachedResponsivePrecommitValue.d.cts} +2 -3
  17. package/dist/useCachedResponsivePrecommitValue.d.cts.map +1 -0
  18. package/dist/useCachedResponsivePrecommitValue.d.mts +0 -1
  19. package/dist/useCachedResponsivePrecommitValue.d.mts.map +1 -1
  20. package/dist/{useDisposableState.js → useDisposableState.cjs} +2 -4
  21. package/dist/{useDisposableState.d.ts → useDisposableState.d.cts} +3 -3
  22. package/dist/useDisposableState.d.cts.map +1 -0
  23. package/dist/useDisposableState.d.mts.map +1 -1
  24. package/dist/useDisposableState.mjs.map +1 -1
  25. package/dist/{useHasCommittedRef.js → useHasCommittedRef.cjs} +0 -2
  26. package/dist/{useHasCommittedRef.d.ts → useHasCommittedRef.d.cts} +1 -2
  27. package/dist/useHasCommittedRef.d.cts.map +1 -0
  28. package/dist/useHasCommittedRef.d.mts +0 -1
  29. package/dist/useHasCommittedRef.d.mts.map +1 -1
  30. package/dist/{useLazyDisposableState.js → useLazyDisposableState.cjs} +3 -3
  31. package/dist/{useLazyDisposableState.d.ts → useLazyDisposableState.d.cts} +3 -4
  32. package/dist/useLazyDisposableState.d.cts.map +1 -0
  33. package/dist/useLazyDisposableState.d.mts +0 -1
  34. package/dist/useLazyDisposableState.d.mts.map +1 -1
  35. package/dist/useLazyDisposableState.mjs.map +1 -1
  36. package/dist/{useUpdatableDisposableState.js → useUpdatableDisposableState.cjs} +1 -3
  37. package/dist/{useUpdatableDisposableState.d.ts → useUpdatableDisposableState.d.cts} +1 -1
  38. package/dist/useUpdatableDisposableState.d.cts.map +1 -0
  39. package/dist/useUpdatableDisposableState.d.mts.map +1 -1
  40. package/dist/useUpdatableDisposableState.mjs.map +1 -1
  41. package/package.json +6 -6
  42. package/src/useLazyDisposableState.ts +1 -1
  43. package/tsconfig.json +2 -4
  44. package/dist/CacheItem.d.ts.map +0 -1
  45. package/dist/ParentCache.d.ts.map +0 -1
  46. package/dist/_virtual/rolldown_runtime.js +0 -25
  47. package/dist/useCachedResponsivePrecommitValue.d.ts.map +0 -1
  48. package/dist/useDisposableState.d.ts.map +0 -1
  49. package/dist/useHasCommittedRef.d.ts.map +0 -1
  50. package/dist/useLazyDisposableState.d.ts.map +0 -1
  51. package/dist/useUpdatableDisposableState.d.ts.map +0 -1
  52. package/tsconfig.pkg.json +0 -9
  53. /package/dist/{CacheItem.js → CacheItem.cjs} +0 -0
@@ -1,11 +1,11 @@
1
1
  ../.. |  WARN  Unsupported engine: wanted: {"node":"24.12.0"} (current: {"node":"v22.22.0","pnpm":"10.15.0"})
2
2
 
3
- > @isograph/react-disposable-state@0.0.0-main-a840a70e compile-libs /home/runner/work/isograph/isograph/libs/isograph-react-disposable-state
3
+ > @isograph/react-disposable-state@0.0.0-main-c09c9dbf compile-libs /home/runner/work/isograph/isograph/libs/isograph-react-disposable-state
4
4
  > tsdown
5
5
 
6
- ℹ tsdown v0.15.10 powered by rolldown v1.0.0-beta.44
7
- ℹ Using tsdown config: /home/runner/work/isograph/isograph/tsdown.config.ts
8
- (node:2780) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/isograph/isograph/tsdown.config.ts is not specified and it doesn't parse as CommonJS.
6
+ ℹ tsdown v0.20.1 powered by rolldown v1.0.0-rc.1
7
+ ℹ config file: /home/runner/work/isograph/isograph/tsdown.config.ts
8
+ (node:2724) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/isograph/isograph/tsdown.config.ts?no-cache=56ad6398-1bb3-432a-a57f-fa1164625a3d is not specified and it doesn't parse as CommonJS.
9
9
  Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
10
10
  To eliminate this warning, add "type": "module" to /home/runner/work/isograph/isograph/package.json.
11
11
  (Use `node --trace-warnings ...` to show where the warning was created)
@@ -1,5 +1,5 @@
1
1
  ../.. |  WARN  Unsupported engine: wanted: {"node":"24.12.0"} (current: {"node":"v22.22.0","pnpm":"10.15.0"})
2
2
 
3
- > @isograph/react-disposable-state@0.0.0-main-a840a70e tsc /home/runner/work/isograph/isograph/libs/isograph-react-disposable-state
3
+ > @isograph/react-disposable-state@0.0.0-main-c09c9dbf tsc /home/runner/work/isograph/isograph/libs/isograph-react-disposable-state
4
4
  > tsc
5
5
 
@@ -60,4 +60,4 @@ declare class CacheItem<T> {
60
60
  declare function createTemporarilyRetainedCacheItem<T>(factory: Factory<T>, removeFromParentCache: CleanupFn, options: CacheItemOptions | void): [CacheItem<T>, CleanupFn];
61
61
  //#endregion
62
62
  export { CacheItem, CacheItemOptions, CacheItemState, InParentCacheAndNotDisposed, NotInParentCacheAndDisposed, NotInParentCacheAndNotDisposed, createTemporarilyRetainedCacheItem };
63
- //# sourceMappingURL=CacheItem.d.ts.map
63
+ //# sourceMappingURL=CacheItem.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheItem.d.cts","names":[],"sources":["../src/CacheItem.ts"],"mappings":";;;KAQY,2BAAA;EACV,IAAA;AAAA;AAAA,KAEU,8BAAA;EACV,IAAA;EACA,KAAA,EAAO,CAAA;EACP,YAAA;EAGA,oBAAA;AAAA;AAAA,KAEU,2BAAA;EACV,IAAA;EACA,KAAA,EAAO,CAAA;EACP,YAAA;EACA,qBAAA;EAGA,oBAAA;EAGA,oBAAA;AAAA;AAAA,KAGU,cAAA,MACR,2BAAA,CAA4B,CAAA,IAC5B,8BAAA,CAA+B,CAAA,IAC/B,2BAAA;AAAA,KAEQ,gBAAA;EACV,mBAAA;AAAA;;;;;;;;;;;;;AANF;;;;;;;;;;;;cAoCa,SAAA;EAAA,QACH,OAAA;EAAA,QACA,SAAA;cAQN,OAAA,EAAS,OAAA,CAAQ,CAAA,GACjB,qBAAA,EAAuB,SAAA,EACvB,OAAA,EAAS,gBAAA;EAgBX,QAAA,CAAA,GAAY,CAAA;EAiBZ,4BAAA,CACE,wBAAA,EAA0B,SAAA,GACzB,eAAA,CAAgB,CAAA;EA+EnB,eAAA,CAAA,GAAmB,SAAA;EAqEnB,eAAA,CAAA,GAAmB,SAAA;EAAA,QAqEX,2CAAA;EAAA,QAoBA,8CAAA;AAAA;AAAA,iBAYM,kCAAA,GAAA,CACd,OAAA,EAAS,OAAA,CAAQ,CAAA,GACjB,qBAAA,EAAuB,SAAA,EACvB,OAAA,EAAS,gBAAA,WACP,SAAA,CAAU,CAAA,GAAI,SAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"CacheItem.d.mts","names":[],"sources":["../src/CacheItem.ts"],"sourcesContent":[],"mappings":";;;KAQY,2BAAA;;AAAZ,CAAA;AAGY,KAAA,8BAA8B,CAAA,CAAA,CAAA,GAAA;EAQ9B,IAAA,EAAA,gCAA2B;EAa3B,KAAA,EAnBH,CAmBG;EACoB,YAAA,EAAA,GAAA,GAAA,IAAA;EAA5B,oBAAA,EAAA,MAAA;CAC+B;AAA/B,KAfQ,2BAeR,CAAA,CAAA,CAAA,GAAA;EACA,IAAA,EAAA,6BAAA;EAA2B,KAAA,EAdtB,CAcsB;EAEnB,YAAA,EAAA,GAAA,GAAgB,IAAA;EA+Bf,qBAAS,EAAA,GAAA,GAAA,IAAA;EAUD,oBAAA,EAAA,MAAA;EAAR,oBAAA,EAAA,MAAA;CACc;AACd,KAhDD,cAgDC,CAAA,CAAA,CAAA,GA/CT,2BA+CS,CA/CmB,CA+CnB,CAAA,GA9CT,8BA8CS,CA9CsB,CA8CtB,CAAA,GA7CT,2BA6CS;AAgBC,KA3DF,gBAAA,GA2DE;EAkBgB,mBAAA,EAAA,MAAA;CACT;;;;;AAyPrB;;;;;;;;;;;;;;;;;;;;cAxSa;;;uBAUA,QAAQ,2BACM,oBACd;cAgBC;yDAkBgB,YACzB,gBAAgB;qBA+EA;qBAqEA;;;;iBAqGL,+CACL,QAAQ,2BACM,oBACd,2BACP,UAAU,IAAI"}
1
+ {"version":3,"file":"CacheItem.d.mts","names":[],"sources":["../src/CacheItem.ts"],"mappings":";;;KAQY,2BAAA;EACV,IAAA;AAAA;AAAA,KAEU,8BAAA;EACV,IAAA;EACA,KAAA,EAAO,CAAA;EACP,YAAA;EAGA,oBAAA;AAAA;AAAA,KAEU,2BAAA;EACV,IAAA;EACA,KAAA,EAAO,CAAA;EACP,YAAA;EACA,qBAAA;EAGA,oBAAA;EAGA,oBAAA;AAAA;AAAA,KAGU,cAAA,MACR,2BAAA,CAA4B,CAAA,IAC5B,8BAAA,CAA+B,CAAA,IAC/B,2BAAA;AAAA,KAEQ,gBAAA;EACV,mBAAA;AAAA;;;;;;;;;;;;;AANF;;;;;;;;;;;;cAoCa,SAAA;EAAA,QACH,OAAA;EAAA,QACA,SAAA;cAQN,OAAA,EAAS,OAAA,CAAQ,CAAA,GACjB,qBAAA,EAAuB,SAAA,EACvB,OAAA,EAAS,gBAAA;EAgBX,QAAA,CAAA,GAAY,CAAA;EAiBZ,4BAAA,CACE,wBAAA,EAA0B,SAAA,GACzB,eAAA,CAAgB,CAAA;EA+EnB,eAAA,CAAA,GAAmB,SAAA;EAqEnB,eAAA,CAAA,GAAmB,SAAA;EAAA,QAqEX,2CAAA;EAAA,QAoBA,8CAAA;AAAA;AAAA,iBAYM,kCAAA,GAAA,CACd,OAAA,EAAS,OAAA,CAAQ,CAAA,GACjB,qBAAA,EAAuB,SAAA,EACvB,OAAA,EAAS,gBAAA,WACP,SAAA,CAAU,CAAA,GAAI,SAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"CacheItem.mjs","names":["status: TemporaryRetainStatus","clearTemporaryRetainByCallack: CleanupFn"],"sources":["../src/CacheItem.ts"],"sourcesContent":["import type {\n CleanupFn,\n Factory,\n ItemCleanupPair,\n} from '@isograph/disposable-types';\n\nconst DEFAULT_TEMPORARY_RETAIN_TIME = 5000;\n\nexport type NotInParentCacheAndDisposed = {\n kind: 'NotInParentCacheAndDisposed';\n};\nexport type NotInParentCacheAndNotDisposed<T> = {\n kind: 'NotInParentCacheAndNotDisposed';\n value: T;\n disposeValue: () => void;\n\n // Invariant: >0\n permanentRetainCount: number;\n};\nexport type InParentCacheAndNotDisposed<T> = {\n kind: 'InParentCacheAndNotDisposed';\n value: T;\n disposeValue: () => void;\n removeFromParentCache: () => void;\n\n // Invariant: >0\n temporaryRetainCount: number;\n\n // Invariant: >= 0\n permanentRetainCount: number;\n};\n\nexport type CacheItemState<T> =\n | InParentCacheAndNotDisposed<T>\n | NotInParentCacheAndNotDisposed<T>\n | NotInParentCacheAndDisposed;\n\nexport type CacheItemOptions = {\n temporaryRetainTime: number;\n};\n\n// TODO don't export this class, only export type (interface) instead\n// TODO convert cacheitem impl to a getter and setter and free functions\n\n/**\n * CacheItem:\n *\n * Terminology:\n * - TRC = Temporary Retain Count\n * - PRC = Permanent Retain Count\n *\n * A CacheItem<T> can be in three states:\n * In parent cache? | Item disposed? | TRC | PRC | Name\n * -----------------+----------------+-----+-----+-------------------------------\n * In parent cache | Not disposed | >0 | >=0 | InParentCacheAndNotDisposed\n * Removed | Not disposed | 0 | >0 | NotInParentCacheAndNotDisposed\n * Removed | Disposed | 0 | 0 | NotInParentCacheAndNotDisposed\n *\n * A cache item can only move down rows. As in, if its in the parent cache,\n * it can be removed. It can never be replaced in the parent cache. (If a\n * parent cache becomes full again, it will contain a new CacheItem.) The\n * contained item can be disposed, but never un-disposed.\n *\n * So, the valid transitions are:\n * - InParentCacheAndNotDisposed => NotInParentCacheAndNotDisposed\n * - InParentCacheAndNotDisposed => NotInParentCacheAndDisposed\n * - NotInParentCacheAndNotDisposed => NotInParentCacheAndDisposed\n */\nexport class CacheItem<T> {\n private __state: CacheItemState<T>;\n private __options: CacheItemOptions | null;\n\n // Private. Do not call this constructor directly. Use\n // createTemporarilyRetainedCacheItem instead. This is because this\n // constructor creates a CacheItem in an invalid state. It must be\n // temporarily retained to enter a valid state, and JavaScript doesn't\n // let you return a tuple from a constructor.\n constructor(\n factory: Factory<T>,\n removeFromParentCache: CleanupFn,\n options: CacheItemOptions | void,\n ) {\n this.__options = options ?? null;\n const [value, disposeValue] = factory();\n this.__state = {\n kind: 'InParentCacheAndNotDisposed',\n value,\n disposeValue,\n removeFromParentCache,\n // NOTE: we are creating the CacheItem in an invalid state. This is okay, because\n // we are immediately calling .temporaryRetain.\n temporaryRetainCount: 0,\n permanentRetainCount: 0,\n };\n }\n\n getValue(): T {\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n return this.__state.value;\n }\n case 'NotInParentCacheAndNotDisposed': {\n return this.__state.value;\n }\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'Attempted to access disposed value from CacheItem. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n }\n\n permanentRetainIfNotDisposed(\n disposeOfTemporaryRetain: CleanupFn,\n ): ItemCleanupPair<T> | null {\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n let cleared = false;\n this.__state.permanentRetainCount++;\n disposeOfTemporaryRetain();\n return [\n this.__state.value,\n () => {\n if (cleared) {\n throw new Error(\n 'A permanent retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n cleared = true;\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'NotInParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitNotInParentCacheAndNotDisposedState(\n this.__state,\n );\n return;\n }\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'CacheItem was in a disposed state, but there existed a permanent retain. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n },\n ];\n }\n case 'NotInParentCacheAndNotDisposed': {\n let cleared = false;\n this.__state.permanentRetainCount++;\n disposeOfTemporaryRetain();\n return [\n this.__state.value,\n () => {\n if (cleared) {\n throw new Error(\n 'A permanent retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n cleared = true;\n switch (this.__state.kind) {\n case 'NotInParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitNotInParentCacheAndNotDisposedState(\n this.__state,\n );\n return;\n }\n case 'InParentCacheAndNotDisposed':\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'CacheItem was in an unexpected state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n },\n ];\n }\n case 'NotInParentCacheAndDisposed': {\n // The CacheItem is disposed, so disposeOfTemporaryRetain is a no-op\n return null;\n }\n }\n }\n\n temporaryRetain(): CleanupFn {\n type TemporaryRetainStatus =\n | 'Uncleared'\n | 'ClearedByCallback'\n | 'ClearedByTimeout';\n\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n let status: TemporaryRetainStatus = 'Uncleared';\n this.__state.temporaryRetainCount++;\n const clearTemporaryRetainByCallack: CleanupFn = () => {\n if (status === 'ClearedByCallback') {\n throw new Error(\n 'A temporary retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n } else if (status === 'Uncleared') {\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n this.__state.temporaryRetainCount--;\n this.__maybeExitInParentCacheAndNotDisposedState(this.__state);\n clearTimeout(timeoutId);\n return;\n }\n case 'NotInParentCacheAndDisposed':\n case 'NotInParentCacheAndNotDisposed': {\n throw new Error(\n 'A temporary retain was cleared, for which the CacheItem is in an invalid state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n }\n };\n\n const clearTemporaryRetainByTimeout = () => {\n status = 'ClearedByTimeout';\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n this.__state.temporaryRetainCount--;\n this.__maybeExitInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'NotInParentCacheAndDisposed':\n case 'NotInParentCacheAndNotDisposed': {\n throw new Error(\n 'A temporary retain was cleared, for which the CacheItem is in an invalid state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n };\n\n const timeoutId = setTimeout(\n clearTemporaryRetainByTimeout,\n this.__options?.temporaryRetainTime ?? DEFAULT_TEMPORARY_RETAIN_TIME,\n );\n return clearTemporaryRetainByCallack;\n }\n case 'NotInParentCacheAndDisposed':\n case 'NotInParentCacheAndNotDisposed': {\n throw new Error(\n 'temporaryRetain was called, for which the CacheItem is in an invalid state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n }\n\n permanentRetain(): CleanupFn {\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n let cleared = false;\n this.__state.permanentRetainCount++;\n return () => {\n if (cleared) {\n throw new Error(\n 'A permanent retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n cleared = true;\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'NotInParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitNotInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'CacheItem was in a disposed state, but there existed a permanent retain. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n };\n }\n case 'NotInParentCacheAndNotDisposed': {\n let cleared = false;\n this.__state.permanentRetainCount++;\n return () => {\n if (cleared) {\n throw new Error(\n 'A permanent retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n cleared = true;\n switch (this.__state.kind) {\n case 'NotInParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitNotInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'InParentCacheAndNotDisposed':\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'CacheItem was in an unexpected state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n };\n }\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'permanentRetain was called, but the CacheItem is in an invalid state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n }\n\n private __maybeExitInParentCacheAndNotDisposedState(\n state: InParentCacheAndNotDisposed<T>,\n ) {\n if (state.temporaryRetainCount === 0 && state.permanentRetainCount === 0) {\n state.removeFromParentCache();\n state.disposeValue();\n this.__state = {\n kind: 'NotInParentCacheAndDisposed',\n };\n } else if (state.temporaryRetainCount === 0) {\n state.removeFromParentCache();\n this.__state = {\n kind: 'NotInParentCacheAndNotDisposed',\n value: state.value,\n disposeValue: state.disposeValue,\n permanentRetainCount: state.permanentRetainCount,\n };\n }\n }\n\n private __maybeExitNotInParentCacheAndNotDisposedState(\n state: NotInParentCacheAndNotDisposed<T>,\n ) {\n if (state.permanentRetainCount === 0) {\n state.disposeValue();\n this.__state = {\n kind: 'NotInParentCacheAndDisposed',\n };\n }\n }\n}\n\nexport function createTemporarilyRetainedCacheItem<T>(\n factory: Factory<T>,\n removeFromParentCache: CleanupFn,\n options: CacheItemOptions | void,\n): [CacheItem<T>, CleanupFn] {\n const cacheItem = new CacheItem(factory, removeFromParentCache, options);\n const disposeTemporaryRetain = cacheItem.temporaryRetain();\n return [cacheItem, disposeTemporaryRetain];\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"CacheItem.mjs","names":[],"sources":["../src/CacheItem.ts"],"sourcesContent":["import type {\n CleanupFn,\n Factory,\n ItemCleanupPair,\n} from '@isograph/disposable-types';\n\nconst DEFAULT_TEMPORARY_RETAIN_TIME = 5000;\n\nexport type NotInParentCacheAndDisposed = {\n kind: 'NotInParentCacheAndDisposed';\n};\nexport type NotInParentCacheAndNotDisposed<T> = {\n kind: 'NotInParentCacheAndNotDisposed';\n value: T;\n disposeValue: () => void;\n\n // Invariant: >0\n permanentRetainCount: number;\n};\nexport type InParentCacheAndNotDisposed<T> = {\n kind: 'InParentCacheAndNotDisposed';\n value: T;\n disposeValue: () => void;\n removeFromParentCache: () => void;\n\n // Invariant: >0\n temporaryRetainCount: number;\n\n // Invariant: >= 0\n permanentRetainCount: number;\n};\n\nexport type CacheItemState<T> =\n | InParentCacheAndNotDisposed<T>\n | NotInParentCacheAndNotDisposed<T>\n | NotInParentCacheAndDisposed;\n\nexport type CacheItemOptions = {\n temporaryRetainTime: number;\n};\n\n// TODO don't export this class, only export type (interface) instead\n// TODO convert cacheitem impl to a getter and setter and free functions\n\n/**\n * CacheItem:\n *\n * Terminology:\n * - TRC = Temporary Retain Count\n * - PRC = Permanent Retain Count\n *\n * A CacheItem<T> can be in three states:\n * In parent cache? | Item disposed? | TRC | PRC | Name\n * -----------------+----------------+-----+-----+-------------------------------\n * In parent cache | Not disposed | >0 | >=0 | InParentCacheAndNotDisposed\n * Removed | Not disposed | 0 | >0 | NotInParentCacheAndNotDisposed\n * Removed | Disposed | 0 | 0 | NotInParentCacheAndNotDisposed\n *\n * A cache item can only move down rows. As in, if its in the parent cache,\n * it can be removed. It can never be replaced in the parent cache. (If a\n * parent cache becomes full again, it will contain a new CacheItem.) The\n * contained item can be disposed, but never un-disposed.\n *\n * So, the valid transitions are:\n * - InParentCacheAndNotDisposed => NotInParentCacheAndNotDisposed\n * - InParentCacheAndNotDisposed => NotInParentCacheAndDisposed\n * - NotInParentCacheAndNotDisposed => NotInParentCacheAndDisposed\n */\nexport class CacheItem<T> {\n private __state: CacheItemState<T>;\n private __options: CacheItemOptions | null;\n\n // Private. Do not call this constructor directly. Use\n // createTemporarilyRetainedCacheItem instead. This is because this\n // constructor creates a CacheItem in an invalid state. It must be\n // temporarily retained to enter a valid state, and JavaScript doesn't\n // let you return a tuple from a constructor.\n constructor(\n factory: Factory<T>,\n removeFromParentCache: CleanupFn,\n options: CacheItemOptions | void,\n ) {\n this.__options = options ?? null;\n const [value, disposeValue] = factory();\n this.__state = {\n kind: 'InParentCacheAndNotDisposed',\n value,\n disposeValue,\n removeFromParentCache,\n // NOTE: we are creating the CacheItem in an invalid state. This is okay, because\n // we are immediately calling .temporaryRetain.\n temporaryRetainCount: 0,\n permanentRetainCount: 0,\n };\n }\n\n getValue(): T {\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n return this.__state.value;\n }\n case 'NotInParentCacheAndNotDisposed': {\n return this.__state.value;\n }\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'Attempted to access disposed value from CacheItem. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n }\n\n permanentRetainIfNotDisposed(\n disposeOfTemporaryRetain: CleanupFn,\n ): ItemCleanupPair<T> | null {\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n let cleared = false;\n this.__state.permanentRetainCount++;\n disposeOfTemporaryRetain();\n return [\n this.__state.value,\n () => {\n if (cleared) {\n throw new Error(\n 'A permanent retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n cleared = true;\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'NotInParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitNotInParentCacheAndNotDisposedState(\n this.__state,\n );\n return;\n }\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'CacheItem was in a disposed state, but there existed a permanent retain. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n },\n ];\n }\n case 'NotInParentCacheAndNotDisposed': {\n let cleared = false;\n this.__state.permanentRetainCount++;\n disposeOfTemporaryRetain();\n return [\n this.__state.value,\n () => {\n if (cleared) {\n throw new Error(\n 'A permanent retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n cleared = true;\n switch (this.__state.kind) {\n case 'NotInParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitNotInParentCacheAndNotDisposedState(\n this.__state,\n );\n return;\n }\n case 'InParentCacheAndNotDisposed':\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'CacheItem was in an unexpected state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n },\n ];\n }\n case 'NotInParentCacheAndDisposed': {\n // The CacheItem is disposed, so disposeOfTemporaryRetain is a no-op\n return null;\n }\n }\n }\n\n temporaryRetain(): CleanupFn {\n type TemporaryRetainStatus =\n | 'Uncleared'\n | 'ClearedByCallback'\n | 'ClearedByTimeout';\n\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n let status: TemporaryRetainStatus = 'Uncleared';\n this.__state.temporaryRetainCount++;\n const clearTemporaryRetainByCallack: CleanupFn = () => {\n if (status === 'ClearedByCallback') {\n throw new Error(\n 'A temporary retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n } else if (status === 'Uncleared') {\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n this.__state.temporaryRetainCount--;\n this.__maybeExitInParentCacheAndNotDisposedState(this.__state);\n clearTimeout(timeoutId);\n return;\n }\n case 'NotInParentCacheAndDisposed':\n case 'NotInParentCacheAndNotDisposed': {\n throw new Error(\n 'A temporary retain was cleared, for which the CacheItem is in an invalid state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n }\n };\n\n const clearTemporaryRetainByTimeout = () => {\n status = 'ClearedByTimeout';\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n this.__state.temporaryRetainCount--;\n this.__maybeExitInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'NotInParentCacheAndDisposed':\n case 'NotInParentCacheAndNotDisposed': {\n throw new Error(\n 'A temporary retain was cleared, for which the CacheItem is in an invalid state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n };\n\n const timeoutId = setTimeout(\n clearTemporaryRetainByTimeout,\n this.__options?.temporaryRetainTime ?? DEFAULT_TEMPORARY_RETAIN_TIME,\n );\n return clearTemporaryRetainByCallack;\n }\n case 'NotInParentCacheAndDisposed':\n case 'NotInParentCacheAndNotDisposed': {\n throw new Error(\n 'temporaryRetain was called, for which the CacheItem is in an invalid state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n }\n\n permanentRetain(): CleanupFn {\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n let cleared = false;\n this.__state.permanentRetainCount++;\n return () => {\n if (cleared) {\n throw new Error(\n 'A permanent retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n cleared = true;\n switch (this.__state.kind) {\n case 'InParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'NotInParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitNotInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'CacheItem was in a disposed state, but there existed a permanent retain. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n };\n }\n case 'NotInParentCacheAndNotDisposed': {\n let cleared = false;\n this.__state.permanentRetainCount++;\n return () => {\n if (cleared) {\n throw new Error(\n 'A permanent retain should only be cleared once. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n cleared = true;\n switch (this.__state.kind) {\n case 'NotInParentCacheAndNotDisposed': {\n this.__state.permanentRetainCount--;\n this.__maybeExitNotInParentCacheAndNotDisposedState(this.__state);\n return;\n }\n case 'InParentCacheAndNotDisposed':\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'CacheItem was in an unexpected state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n };\n }\n case 'NotInParentCacheAndDisposed': {\n throw new Error(\n 'permanentRetain was called, but the CacheItem is in an invalid state. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n }\n\n private __maybeExitInParentCacheAndNotDisposedState(\n state: InParentCacheAndNotDisposed<T>,\n ) {\n if (state.temporaryRetainCount === 0 && state.permanentRetainCount === 0) {\n state.removeFromParentCache();\n state.disposeValue();\n this.__state = {\n kind: 'NotInParentCacheAndDisposed',\n };\n } else if (state.temporaryRetainCount === 0) {\n state.removeFromParentCache();\n this.__state = {\n kind: 'NotInParentCacheAndNotDisposed',\n value: state.value,\n disposeValue: state.disposeValue,\n permanentRetainCount: state.permanentRetainCount,\n };\n }\n }\n\n private __maybeExitNotInParentCacheAndNotDisposedState(\n state: NotInParentCacheAndNotDisposed<T>,\n ) {\n if (state.permanentRetainCount === 0) {\n state.disposeValue();\n this.__state = {\n kind: 'NotInParentCacheAndDisposed',\n };\n }\n }\n}\n\nexport function createTemporarilyRetainedCacheItem<T>(\n factory: Factory<T>,\n removeFromParentCache: CleanupFn,\n options: CacheItemOptions | void,\n): [CacheItem<T>, CleanupFn] {\n const cacheItem = new CacheItem(factory, removeFromParentCache, options);\n const disposeTemporaryRetain = cacheItem.temporaryRetain();\n return [cacheItem, disposeTemporaryRetain];\n}\n"],"mappings":"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"}
@@ -1,4 +1,4 @@
1
- const require_CacheItem = require('./CacheItem.js');
1
+ const require_CacheItem = require('./CacheItem.cjs');
2
2
 
3
3
  //#region src/ParentCache.ts
4
4
  /**
@@ -1,8 +1,7 @@
1
- import { CacheItem } from "./CacheItem.js";
1
+ import { CacheItem } from "./CacheItem.cjs";
2
2
  import { CleanupFn, Factory, ItemCleanupPair } from "@isograph/disposable-types";
3
3
 
4
4
  //#region src/ParentCache.d.ts
5
-
6
5
  /**
7
6
  * ParentCache
8
7
  * - A ParentCache can be in two states: populated and unpopulated.
@@ -42,4 +41,4 @@ declare class ParentCache<T> {
42
41
  }
43
42
  //#endregion
44
43
  export { ParentCache };
45
- //# sourceMappingURL=ParentCache.d.ts.map
44
+ //# sourceMappingURL=ParentCache.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ParentCache.d.cts","names":[],"sources":["../src/ParentCache.ts"],"mappings":";;;;;;AA2BA;;;;;;;;;;;;;;cAAa,WAAA;EAAA,QACH,WAAA;EAAA,iBACS,SAAA;cAIL,OAAA,EAAS,OAAA,CAAQ,CAAA;;;;;;;;;;;EAc7B,8BAAA,CAAA,GAAkC,eAAA,CAAgB,CAAA;EAMlD,+BAAA,CAAA,IAAoC,SAAA,CAAU,CAAA,GAAI,CAAA,EAAG,SAAA;EAAA,QAM7C,4BAAA;EA4BR,KAAA,CAAA;EAAA,IAII,OAAA,CAAA,GAAW,OAAA,CAAQ,CAAA;EAIvB,OAAA,CAAA;AAAA"}
@@ -2,7 +2,6 @@ import { CacheItem } from "./CacheItem.mjs";
2
2
  import { CleanupFn, Factory, ItemCleanupPair } from "@isograph/disposable-types";
3
3
 
4
4
  //#region src/ParentCache.d.ts
5
-
6
5
  /**
7
6
  * ParentCache
8
7
  * - A ParentCache can be in two states: populated and unpopulated.
@@ -1 +1 @@
1
- {"version":3,"file":"ParentCache.d.mts","names":[],"sources":["../src/ParentCache.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2BA;;;;;;;;;;;;;;cAAa;;;uBAMU,QAAQ;;;;;;;;;;;oCAcK,gBAAgB;sCAMd,UAAU,IAAI,GAAG;;;iBAsCtC,QAAQ"}
1
+ {"version":3,"file":"ParentCache.d.mts","names":[],"sources":["../src/ParentCache.ts"],"mappings":";;;;;;AA2BA;;;;;;;;;;;;;;cAAa,WAAA;EAAA,QACH,WAAA;EAAA,iBACS,SAAA;cAIL,OAAA,EAAS,OAAA,CAAQ,CAAA;;;;;;;;;;;EAc7B,8BAAA,CAAA,GAAkC,eAAA,CAAgB,CAAA;EAMlD,+BAAA,CAAA,IAAoC,SAAA,CAAU,CAAA,GAAI,CAAA,EAAG,SAAA;EAAA,QAM7C,4BAAA;EA4BR,KAAA,CAAA;EAAA,IAII,OAAA,CAAA,GAAW,OAAA,CAAQ,CAAA;EAIvB,OAAA,CAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"ParentCache.mjs","names":["pair: ItemCleanupPair<CacheItem<T>>"],"sources":["../src/ParentCache.ts"],"sourcesContent":["import type {\n CleanupFn,\n Factory,\n ItemCleanupPair,\n} from '@isograph/disposable-types';\nimport type { CacheItem } from './CacheItem';\nimport { createTemporarilyRetainedCacheItem } from './CacheItem';\n\n// TODO convert cache impl to a getter and setter and free functions\n// TODO accept options that get passed to CacheItem\n\n/**\n * ParentCache\n * - A ParentCache can be in two states: populated and unpopulated.\n * - A ParentCache holds a CacheItem, which can choose to remove itself from\n * the parent ParentCache.\n * - If the ParentCache is populated, the CacheItem (i.e. this.__value) must be\n * in the InParentCacheAndNotDisposed state, i.e. not disposed, so after we\n * null-check this.__value, this.__value.getValue(), this.__value.temporaryRetain()\n * and this.__value.permanentRetain() are safe to be called.\n *\n * - Though we do not do so, it is always safe to call parentCache.delete().\n *\n * Invariant:\n * - A parent cache at a given \"location\" (conceptually, an ID) should always\n * be called\n */\nexport class ParentCache<T> {\n private __cacheItem: CacheItem<T> | null = null;\n private readonly __factory: Factory<T>;\n\n // TODO pass an onEmpty function, which can e.g. remove this ParentCache\n // from some parent object.\n constructor(factory: Factory<T>) {\n this.__factory = factory;\n }\n\n /**\n * This is called from useCachedResponsivePrecommitValue, when the parent cache is populated\n * and a previous temporary retain has been disposed. This can occur in scenarios like:\n * - temporary retain A is created by component B rendering\n * - temporary retain A expires, emptying the parent cache\n * - another component renders, sharing the same parent cache, filling\n * by calling getOrPopulateAndTemporaryRetain\n * - component B commits. We see that temporary retain A has been disposed,\n * and re-check the parent cache by calling this method.\n */\n getAndPermanentRetainIfPresent(): ItemCleanupPair<T> | null {\n return this.__cacheItem != null\n ? [this.__cacheItem.getValue(), this.__cacheItem.permanentRetain()]\n : null;\n }\n\n getOrPopulateAndTemporaryRetain(): [CacheItem<T>, T, CleanupFn] {\n return this.__cacheItem == null\n ? this.__populateAndTemporaryRetain()\n : temporaryRetain(this.__cacheItem);\n }\n\n private __populateAndTemporaryRetain(): [CacheItem<T>, T, CleanupFn] {\n const pair: ItemCleanupPair<CacheItem<T>> =\n createTemporarilyRetainedCacheItem(this.__factory, () => {\n // We are doing this check because we don't want to remove the cache item\n // if it is not the one that was created when the temporary retain was created.\n //\n // Consider the following scenario:\n // - we populate the cache with CacheItem A,\n // - then manually delete CacheItem A (e.g. to force a refetch)\n // - then, we re-populate the parent cache with CacheItem B\n // - then, the temporary retain of CacheItem A is disposed or expires.\n //\n // At this point, we don't want to delete CacheItem B from the cache.\n //\n // TODO consider what happens if items are === comparable to each other,\n // e.g. the item is a number!\n if (this.__cacheItem === pair[0]) {\n this.empty();\n }\n });\n\n // We deconstruct this here instead of at the definition site because otherwise,\n // typescript thinks that cacheItem is any, because it's referenced in the closure.\n const [cacheItem, disposeTemporaryRetain] = pair;\n this.__cacheItem = cacheItem;\n return [cacheItem, cacheItem.getValue(), disposeTemporaryRetain];\n }\n\n empty() {\n this.__cacheItem = null;\n }\n\n get factory(): Factory<T> {\n return this.__factory;\n }\n\n isEmpty(): boolean {\n return this.__cacheItem == null;\n }\n}\n\nfunction temporaryRetain<T>(value: CacheItem<T>): [CacheItem<T>, T, CleanupFn] {\n return [value, value.getValue(), value.temporaryRetain()];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,IAAa,cAAb,MAA4B;CAM1B,YAAY,SAAqB;qBALU;AAMzC,OAAK,YAAY;;;;;;;;;;;;CAanB,iCAA4D;AAC1D,SAAO,KAAK,eAAe,OACvB,CAAC,KAAK,YAAY,UAAU,EAAE,KAAK,YAAY,iBAAiB,CAAC,GACjE;;CAGN,kCAAgE;AAC9D,SAAO,KAAK,eAAe,OACvB,KAAK,8BAA8B,GACnC,gBAAgB,KAAK,YAAY;;CAGvC,AAAQ,+BAA6D;EACnE,MAAMA,OACJ,mCAAmC,KAAK,iBAAiB;AAcvD,OAAI,KAAK,gBAAgB,KAAK,GAC5B,MAAK,OAAO;IAEd;EAIJ,MAAM,CAAC,WAAW,0BAA0B;AAC5C,OAAK,cAAc;AACnB,SAAO;GAAC;GAAW,UAAU,UAAU;GAAE;GAAuB;;CAGlE,QAAQ;AACN,OAAK,cAAc;;CAGrB,IAAI,UAAsB;AACxB,SAAO,KAAK;;CAGd,UAAmB;AACjB,SAAO,KAAK,eAAe;;;AAI/B,SAAS,gBAAmB,OAAmD;AAC7E,QAAO;EAAC;EAAO,MAAM,UAAU;EAAE,MAAM,iBAAiB;EAAC"}
1
+ {"version":3,"file":"ParentCache.mjs","names":[],"sources":["../src/ParentCache.ts"],"sourcesContent":["import type {\n CleanupFn,\n Factory,\n ItemCleanupPair,\n} from '@isograph/disposable-types';\nimport type { CacheItem } from './CacheItem';\nimport { createTemporarilyRetainedCacheItem } from './CacheItem';\n\n// TODO convert cache impl to a getter and setter and free functions\n// TODO accept options that get passed to CacheItem\n\n/**\n * ParentCache\n * - A ParentCache can be in two states: populated and unpopulated.\n * - A ParentCache holds a CacheItem, which can choose to remove itself from\n * the parent ParentCache.\n * - If the ParentCache is populated, the CacheItem (i.e. this.__value) must be\n * in the InParentCacheAndNotDisposed state, i.e. not disposed, so after we\n * null-check this.__value, this.__value.getValue(), this.__value.temporaryRetain()\n * and this.__value.permanentRetain() are safe to be called.\n *\n * - Though we do not do so, it is always safe to call parentCache.delete().\n *\n * Invariant:\n * - A parent cache at a given \"location\" (conceptually, an ID) should always\n * be called\n */\nexport class ParentCache<T> {\n private __cacheItem: CacheItem<T> | null = null;\n private readonly __factory: Factory<T>;\n\n // TODO pass an onEmpty function, which can e.g. remove this ParentCache\n // from some parent object.\n constructor(factory: Factory<T>) {\n this.__factory = factory;\n }\n\n /**\n * This is called from useCachedResponsivePrecommitValue, when the parent cache is populated\n * and a previous temporary retain has been disposed. This can occur in scenarios like:\n * - temporary retain A is created by component B rendering\n * - temporary retain A expires, emptying the parent cache\n * - another component renders, sharing the same parent cache, filling\n * by calling getOrPopulateAndTemporaryRetain\n * - component B commits. We see that temporary retain A has been disposed,\n * and re-check the parent cache by calling this method.\n */\n getAndPermanentRetainIfPresent(): ItemCleanupPair<T> | null {\n return this.__cacheItem != null\n ? [this.__cacheItem.getValue(), this.__cacheItem.permanentRetain()]\n : null;\n }\n\n getOrPopulateAndTemporaryRetain(): [CacheItem<T>, T, CleanupFn] {\n return this.__cacheItem == null\n ? this.__populateAndTemporaryRetain()\n : temporaryRetain(this.__cacheItem);\n }\n\n private __populateAndTemporaryRetain(): [CacheItem<T>, T, CleanupFn] {\n const pair: ItemCleanupPair<CacheItem<T>> =\n createTemporarilyRetainedCacheItem(this.__factory, () => {\n // We are doing this check because we don't want to remove the cache item\n // if it is not the one that was created when the temporary retain was created.\n //\n // Consider the following scenario:\n // - we populate the cache with CacheItem A,\n // - then manually delete CacheItem A (e.g. to force a refetch)\n // - then, we re-populate the parent cache with CacheItem B\n // - then, the temporary retain of CacheItem A is disposed or expires.\n //\n // At this point, we don't want to delete CacheItem B from the cache.\n //\n // TODO consider what happens if items are === comparable to each other,\n // e.g. the item is a number!\n if (this.__cacheItem === pair[0]) {\n this.empty();\n }\n });\n\n // We deconstruct this here instead of at the definition site because otherwise,\n // typescript thinks that cacheItem is any, because it's referenced in the closure.\n const [cacheItem, disposeTemporaryRetain] = pair;\n this.__cacheItem = cacheItem;\n return [cacheItem, cacheItem.getValue(), disposeTemporaryRetain];\n }\n\n empty() {\n this.__cacheItem = null;\n }\n\n get factory(): Factory<T> {\n return this.__factory;\n }\n\n isEmpty(): boolean {\n return this.__cacheItem == null;\n }\n}\n\nfunction temporaryRetain<T>(value: CacheItem<T>): [CacheItem<T>, T, CleanupFn] {\n return [value, value.getValue(), value.temporaryRetain()];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,IAAa,cAAb,MAA4B;CAM1B,YAAY,SAAqB;qBALU;AAMzC,OAAK,YAAY;;;;;;;;;;;;CAanB,iCAA4D;AAC1D,SAAO,KAAK,eAAe,OACvB,CAAC,KAAK,YAAY,UAAU,EAAE,KAAK,YAAY,iBAAiB,CAAC,GACjE;;CAGN,kCAAgE;AAC9D,SAAO,KAAK,eAAe,OACvB,KAAK,8BAA8B,GACnC,gBAAgB,KAAK,YAAY;;CAGvC,AAAQ,+BAA6D;EACnE,MAAM,OACJ,mCAAmC,KAAK,iBAAiB;AAcvD,OAAI,KAAK,gBAAgB,KAAK,GAC5B,MAAK,OAAO;IAEd;EAIJ,MAAM,CAAC,WAAW,0BAA0B;AAC5C,OAAK,cAAc;AACnB,SAAO;GAAC;GAAW,UAAU,UAAU;GAAE;GAAuB;;CAGlE,QAAQ;AACN,OAAK,cAAc;;CAGrB,IAAI,UAAsB;AACxB,SAAO,KAAK;;CAGd,UAAmB;AACjB,SAAO,KAAK,eAAe;;;AAI/B,SAAS,gBAAmB,OAAmD;AAC7E,QAAO;EAAC;EAAO,MAAM,UAAU;EAAE,MAAM,iBAAiB;EAAC"}
@@ -1,10 +1,10 @@
1
- const require_CacheItem = require('./CacheItem.js');
2
- const require_ParentCache = require('./ParentCache.js');
3
- const require_useCachedResponsivePrecommitValue = require('./useCachedResponsivePrecommitValue.js');
4
- const require_useHasCommittedRef = require('./useHasCommittedRef.js');
5
- const require_useUpdatableDisposableState = require('./useUpdatableDisposableState.js');
6
- const require_useDisposableState = require('./useDisposableState.js');
7
- const require_useLazyDisposableState = require('./useLazyDisposableState.js');
1
+ const require_CacheItem = require('./CacheItem.cjs');
2
+ const require_ParentCache = require('./ParentCache.cjs');
3
+ const require_useCachedResponsivePrecommitValue = require('./useCachedResponsivePrecommitValue.cjs');
4
+ const require_useHasCommittedRef = require('./useHasCommittedRef.cjs');
5
+ const require_useUpdatableDisposableState = require('./useUpdatableDisposableState.cjs');
6
+ const require_useDisposableState = require('./useDisposableState.cjs');
7
+ const require_useLazyDisposableState = require('./useLazyDisposableState.cjs');
8
8
 
9
9
  exports.CacheItem = require_CacheItem.CacheItem;
10
10
  exports.ParentCache = require_ParentCache.ParentCache;
@@ -15,10 +15,10 @@ exports.useDisposableState = require_useDisposableState.useDisposableState;
15
15
  exports.useHasCommittedRef = require_useHasCommittedRef.useHasCommittedRef;
16
16
  exports.useLazyDisposableState = require_useLazyDisposableState.useLazyDisposableState;
17
17
  exports.useUpdatableDisposableState = require_useUpdatableDisposableState.useUpdatableDisposableState;
18
- var __isograph_disposable_types = require("@isograph/disposable-types");
19
- Object.keys(__isograph_disposable_types).forEach(function (k) {
18
+ var _isograph_disposable_types = require("@isograph/disposable-types");
19
+ Object.keys(_isograph_disposable_types).forEach(function (k) {
20
20
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
21
21
  enumerable: true,
22
- get: function () { return __isograph_disposable_types[k]; }
22
+ get: function () { return _isograph_disposable_types[k]; }
23
23
  });
24
24
  });
@@ -1,9 +1,9 @@
1
- import { CacheItem, CacheItemOptions, CacheItemState, InParentCacheAndNotDisposed, NotInParentCacheAndDisposed, NotInParentCacheAndNotDisposed, createTemporarilyRetainedCacheItem } from "./CacheItem.js";
2
- import { ParentCache } from "./ParentCache.js";
3
- import { useCachedResponsivePrecommitValue } from "./useCachedResponsivePrecommitValue.js";
4
- import { UNASSIGNED_STATE, UnassignedState, useUpdatableDisposableState } from "./useUpdatableDisposableState.js";
5
- import { useDisposableState } from "./useDisposableState.js";
6
- import { useHasCommittedRef } from "./useHasCommittedRef.js";
7
- import { useLazyDisposableState } from "./useLazyDisposableState.js";
1
+ import { CacheItem, CacheItemOptions, CacheItemState, InParentCacheAndNotDisposed, NotInParentCacheAndDisposed, NotInParentCacheAndNotDisposed, createTemporarilyRetainedCacheItem } from "./CacheItem.cjs";
2
+ import { ParentCache } from "./ParentCache.cjs";
3
+ import { useCachedResponsivePrecommitValue } from "./useCachedResponsivePrecommitValue.cjs";
4
+ import { UNASSIGNED_STATE, UnassignedState, useUpdatableDisposableState } from "./useUpdatableDisposableState.cjs";
5
+ import { useDisposableState } from "./useDisposableState.cjs";
6
+ import { useHasCommittedRef } from "./useHasCommittedRef.cjs";
7
+ import { useLazyDisposableState } from "./useLazyDisposableState.cjs";
8
8
  export * from "@isograph/disposable-types";
9
9
  export { CacheItem, CacheItemOptions, CacheItemState, InParentCacheAndNotDisposed, NotInParentCacheAndDisposed, NotInParentCacheAndNotDisposed, ParentCache, UNASSIGNED_STATE, UnassignedState, createTemporarilyRetainedCacheItem, useCachedResponsivePrecommitValue, useDisposableState, useHasCommittedRef, useLazyDisposableState, useUpdatableDisposableState };
@@ -1,6 +1,6 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
1
+ 'use strict';
2
+
2
3
  let react = require("react");
3
- react = require_rolldown_runtime.__toESM(react);
4
4
 
5
5
  //#region src/useCachedResponsivePrecommitValue.ts
6
6
  /**
@@ -1,8 +1,7 @@
1
- import { ParentCache } from "./ParentCache.js";
1
+ import { ParentCache } from "./ParentCache.cjs";
2
2
  import { ItemCleanupPair } from "@isograph/disposable-types";
3
3
 
4
4
  //#region src/useCachedResponsivePrecommitValue.d.ts
5
-
6
5
  /**
7
6
  * useCachedResponsivePrecommitValue<T>
8
7
  * - Takes a mutable parent cache, a factory function, and an onCommit callback.
@@ -40,4 +39,4 @@ declare function useCachedResponsivePrecommitValue<T>(parentCache: ParentCache<T
40
39
  } | null;
41
40
  //#endregion
42
41
  export { useCachedResponsivePrecommitValue };
43
- //# sourceMappingURL=useCachedResponsivePrecommitValue.d.ts.map
42
+ //# sourceMappingURL=useCachedResponsivePrecommitValue.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCachedResponsivePrecommitValue.d.cts","names":[],"sources":["../src/useCachedResponsivePrecommitValue.ts"],"mappings":";;;;;;AAsCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,iCAAA,GAAA,CACd,WAAA,EAAa,WAAA,CAAY,CAAA,GACzB,QAAA,GAAW,IAAA,EAAM,eAAA,CAAgB,CAAA;EAC9B,KAAA,EAAO,CAAA;AAAA"}
@@ -2,7 +2,6 @@ import { ParentCache } from "./ParentCache.mjs";
2
2
  import { ItemCleanupPair } from "@isograph/disposable-types";
3
3
 
4
4
  //#region src/useCachedResponsivePrecommitValue.d.ts
5
-
6
5
  /**
7
6
  * useCachedResponsivePrecommitValue<T>
8
7
  * - Takes a mutable parent cache, a factory function, and an onCommit callback.
@@ -1 +1 @@
1
- {"version":3,"file":"useCachedResponsivePrecommitValue.d.mts","names":[],"sources":["../src/useCachedResponsivePrecommitValue.ts"],"sourcesContent":[],"mappings":";;;;;;;AAsCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,kDACD,YAAY,qBACR,gBAAgB;SACvB"}
1
+ {"version":3,"file":"useCachedResponsivePrecommitValue.d.mts","names":[],"sources":["../src/useCachedResponsivePrecommitValue.ts"],"mappings":";;;;;;AAsCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,iCAAA,GAAA,CACd,WAAA,EAAa,WAAA,CAAY,CAAA,GACzB,QAAA,GAAW,IAAA,EAAM,eAAA,CAAgB,CAAA;EAC9B,KAAA,EAAO,CAAA;AAAA"}
@@ -1,8 +1,6 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
- const require_useCachedResponsivePrecommitValue = require('./useCachedResponsivePrecommitValue.js');
3
- const require_useUpdatableDisposableState = require('./useUpdatableDisposableState.js');
1
+ const require_useCachedResponsivePrecommitValue = require('./useCachedResponsivePrecommitValue.cjs');
2
+ const require_useUpdatableDisposableState = require('./useUpdatableDisposableState.cjs');
4
3
  let react = require("react");
5
- react = require_rolldown_runtime.__toESM(react);
6
4
 
7
5
  //#region src/useDisposableState.ts
8
6
  function useDisposableState(parentCache) {
@@ -1,5 +1,5 @@
1
- import { ParentCache } from "./ParentCache.js";
2
- import { UnassignedState } from "./useUpdatableDisposableState.js";
1
+ import { ParentCache } from "./ParentCache.cjs";
2
+ import { UnassignedState } from "./useUpdatableDisposableState.cjs";
3
3
  import { ItemCleanupPair } from "@isograph/disposable-types";
4
4
 
5
5
  //#region src/useDisposableState.d.ts
@@ -10,4 +10,4 @@ type UseUpdatableDisposableStateReturnValue<T> = {
10
10
  declare function useDisposableState<T = never>(parentCache: ParentCache<T>): UseUpdatableDisposableStateReturnValue<T>;
11
11
  //#endregion
12
12
  export { useDisposableState };
13
- //# sourceMappingURL=useDisposableState.d.ts.map
13
+ //# sourceMappingURL=useDisposableState.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDisposableState.d.cts","names":[],"sources":["../src/useDisposableState.ts"],"mappings":";;;;;KAUK,sCAAA;EACH,KAAA,EAAO,CAAA;EACP,QAAA,GAAW,IAAA,EAAM,eAAA,CAAgB,OAAA,CAAQ,CAAA,EAAG,eAAA;AAAA;AAAA,iBAG9B,kBAAA,WAAA,CACd,WAAA,EAAa,WAAA,CAAY,CAAA,IACxB,sCAAA,CAAuC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDisposableState.d.mts","names":[],"sources":["../src/useDisposableState.ts"],"sourcesContent":[],"mappings":";;;;;KAUK;SACI;EADJ,QAAA,EAAA,CAAA,IAAA,EAEc,eAFd,CAE8B,OAF9B,CAEsC,CAFA,EAEG,eAFH,CAAA,CAAA,EAAA,GAAA,IAAA;CAClC;AACkC,iBAG3B,kBAH2B,CAAA,IAAA,KAAA,CAAA,CAAA,WAAA,EAI5B,WAJ4B,CAIhB,CAJgB,CAAA,CAAA,EAKxC,sCALwC,CAKD,CALC,CAAA"}
1
+ {"version":3,"file":"useDisposableState.d.mts","names":[],"sources":["../src/useDisposableState.ts"],"mappings":";;;;;KAUK,sCAAA;EACH,KAAA,EAAO,CAAA;EACP,QAAA,GAAW,IAAA,EAAM,eAAA,CAAgB,OAAA,CAAQ,CAAA,EAAG,eAAA;AAAA;AAAA,iBAG9B,kBAAA,WAAA,CACd,WAAA,EAAa,WAAA,CAAY,CAAA,IACxB,sCAAA,CAAuC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDisposableState.mjs","names":["state: T | undefined"],"sources":["../src/useDisposableState.ts"],"sourcesContent":["import type { ItemCleanupPair } from '@isograph/disposable-types';\nimport { useEffect, useRef } from 'react';\nimport type { ParentCache } from './ParentCache';\nimport { useCachedResponsivePrecommitValue } from './useCachedResponsivePrecommitValue';\nimport {\n UNASSIGNED_STATE,\n type UnassignedState,\n useUpdatableDisposableState,\n} from './useUpdatableDisposableState';\n\ntype UseUpdatableDisposableStateReturnValue<T> = {\n state: T;\n setState: (pair: ItemCleanupPair<Exclude<T, UnassignedState>>) => void;\n};\n\nexport function useDisposableState<T = never>(\n parentCache: ParentCache<T>,\n): UseUpdatableDisposableStateReturnValue<T> {\n const itemCleanupPairRef = useRef<ItemCleanupPair<T> | null>(null);\n\n const preCommitItem = useCachedResponsivePrecommitValue(\n parentCache,\n (pair) => {\n itemCleanupPairRef.current?.[1]();\n itemCleanupPairRef.current = pair;\n },\n );\n\n const { state: stateFromDisposableStateHook, setState } =\n useUpdatableDisposableState<T>();\n\n useEffect(\n function cleanupItemCleanupPairRefAfterSetState() {\n if (stateFromDisposableStateHook !== UNASSIGNED_STATE) {\n if (itemCleanupPairRef.current != null) {\n itemCleanupPairRef.current[1]();\n itemCleanupPairRef.current = null;\n } else {\n throw new Error(\n 'itemCleanupPairRef.current is unexpectedly null. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n },\n [stateFromDisposableStateHook],\n );\n\n useEffect(function cleanupItemCleanupPairRefIfSetStateNotCalled() {\n return () => {\n if (itemCleanupPairRef.current != null) {\n itemCleanupPairRef.current[1]();\n itemCleanupPairRef.current = null;\n }\n };\n }, []);\n const state: T | undefined =\n (stateFromDisposableStateHook !== UNASSIGNED_STATE\n ? stateFromDisposableStateHook\n : null) ??\n preCommitItem?.state ??\n itemCleanupPairRef.current?.[0];\n\n if (state != null) {\n return {\n state: state,\n setState,\n };\n }\n\n // Safety: we can be in one of three states. Pre-commit, in which case\n // preCommitItem is assigned, post-commit but before setState has been\n // called, in which case itemCleanupPairRef.current is assigned, or\n // after setState has been called, in which case\n // stateFromDisposableStateHook is assigned.\n //\n // Therefore, the type of state is T, not T | undefined. But the fact\n // that we are in one of the three states is not reflected in the types.\n // So we have to cast to T.\n //\n // Note that in the post-commit post-setState state, itemCleanupPairRef\n // can still be assigned, during the render before the\n // cleanupItemCleanupPairRefAfterSetState effect is called.\n throw new Error(\n 'state was unexpectedly null. This indicates a bug in react-disposable-state.',\n );\n}\n\n// @ts-ignore\nfunction tsTests() {\n let x: any;\n const a = useDisposableState(x);\n // This should be a compiler error, because the generic is inferred to be of\n // type never. TODO determine why this doesn't break the build!\n // @ts-expect-error\n a.setState(['asdf', () => {}]);\n // @ts-expect-error\n a.setState([UNASSIGNED_STATE, () => {}]);\n const b = useDisposableState<string | UnassignedState>(x);\n // @ts-expect-error\n b.setState([UNASSIGNED_STATE, () => {}]);\n b.setState(['asdf', () => {}]);\n}\n"],"mappings":";;;;;AAeA,SAAgB,mBACd,aAC2C;CAC3C,MAAM,qBAAqB,OAAkC,KAAK;CAElE,MAAM,gBAAgB,kCACpB,cACC,SAAS;AACR,qBAAmB,UAAU,IAAI;AACjC,qBAAmB,UAAU;GAEhC;CAED,MAAM,EAAE,OAAO,8BAA8B,aAC3C,6BAAgC;AAElC,WACE,SAAS,yCAAyC;AAChD,MAAI,iCAAiC,iBACnC,KAAI,mBAAmB,WAAW,MAAM;AACtC,sBAAmB,QAAQ,IAAI;AAC/B,sBAAmB,UAAU;QAE7B,OAAM,IAAI,MACR,mGAED;IAIP,CAAC,6BAA6B,CAC/B;AAED,WAAU,SAAS,+CAA+C;AAChE,eAAa;AACX,OAAI,mBAAmB,WAAW,MAAM;AACtC,uBAAmB,QAAQ,IAAI;AAC/B,uBAAmB,UAAU;;;IAGhC,EAAE,CAAC;CACN,MAAMA,SACH,iCAAiC,mBAC9B,+BACA,SACJ,eAAe,SACf,mBAAmB,UAAU;AAE/B,KAAI,SAAS,KACX,QAAO;EACE;EACP;EACD;AAgBH,OAAM,IAAI,MACR,+EACD"}
1
+ {"version":3,"file":"useDisposableState.mjs","names":[],"sources":["../src/useDisposableState.ts"],"sourcesContent":["import type { ItemCleanupPair } from '@isograph/disposable-types';\nimport { useEffect, useRef } from 'react';\nimport type { ParentCache } from './ParentCache';\nimport { useCachedResponsivePrecommitValue } from './useCachedResponsivePrecommitValue';\nimport {\n UNASSIGNED_STATE,\n type UnassignedState,\n useUpdatableDisposableState,\n} from './useUpdatableDisposableState';\n\ntype UseUpdatableDisposableStateReturnValue<T> = {\n state: T;\n setState: (pair: ItemCleanupPair<Exclude<T, UnassignedState>>) => void;\n};\n\nexport function useDisposableState<T = never>(\n parentCache: ParentCache<T>,\n): UseUpdatableDisposableStateReturnValue<T> {\n const itemCleanupPairRef = useRef<ItemCleanupPair<T> | null>(null);\n\n const preCommitItem = useCachedResponsivePrecommitValue(\n parentCache,\n (pair) => {\n itemCleanupPairRef.current?.[1]();\n itemCleanupPairRef.current = pair;\n },\n );\n\n const { state: stateFromDisposableStateHook, setState } =\n useUpdatableDisposableState<T>();\n\n useEffect(\n function cleanupItemCleanupPairRefAfterSetState() {\n if (stateFromDisposableStateHook !== UNASSIGNED_STATE) {\n if (itemCleanupPairRef.current != null) {\n itemCleanupPairRef.current[1]();\n itemCleanupPairRef.current = null;\n } else {\n throw new Error(\n 'itemCleanupPairRef.current is unexpectedly null. ' +\n 'This indicates a bug in react-disposable-state.',\n );\n }\n }\n },\n [stateFromDisposableStateHook],\n );\n\n useEffect(function cleanupItemCleanupPairRefIfSetStateNotCalled() {\n return () => {\n if (itemCleanupPairRef.current != null) {\n itemCleanupPairRef.current[1]();\n itemCleanupPairRef.current = null;\n }\n };\n }, []);\n const state: T | undefined =\n (stateFromDisposableStateHook !== UNASSIGNED_STATE\n ? stateFromDisposableStateHook\n : null) ??\n preCommitItem?.state ??\n itemCleanupPairRef.current?.[0];\n\n if (state != null) {\n return {\n state: state,\n setState,\n };\n }\n\n // Safety: we can be in one of three states. Pre-commit, in which case\n // preCommitItem is assigned, post-commit but before setState has been\n // called, in which case itemCleanupPairRef.current is assigned, or\n // after setState has been called, in which case\n // stateFromDisposableStateHook is assigned.\n //\n // Therefore, the type of state is T, not T | undefined. But the fact\n // that we are in one of the three states is not reflected in the types.\n // So we have to cast to T.\n //\n // Note that in the post-commit post-setState state, itemCleanupPairRef\n // can still be assigned, during the render before the\n // cleanupItemCleanupPairRefAfterSetState effect is called.\n throw new Error(\n 'state was unexpectedly null. This indicates a bug in react-disposable-state.',\n );\n}\n\n// @ts-ignore\nfunction tsTests() {\n let x: any;\n const a = useDisposableState(x);\n // This should be a compiler error, because the generic is inferred to be of\n // type never. TODO determine why this doesn't break the build!\n // @ts-expect-error\n a.setState(['asdf', () => {}]);\n // @ts-expect-error\n a.setState([UNASSIGNED_STATE, () => {}]);\n const b = useDisposableState<string | UnassignedState>(x);\n // @ts-expect-error\n b.setState([UNASSIGNED_STATE, () => {}]);\n b.setState(['asdf', () => {}]);\n}\n"],"mappings":";;;;;AAeA,SAAgB,mBACd,aAC2C;CAC3C,MAAM,qBAAqB,OAAkC,KAAK;CAElE,MAAM,gBAAgB,kCACpB,cACC,SAAS;AACR,qBAAmB,UAAU,IAAI;AACjC,qBAAmB,UAAU;GAEhC;CAED,MAAM,EAAE,OAAO,8BAA8B,aAC3C,6BAAgC;AAElC,WACE,SAAS,yCAAyC;AAChD,MAAI,iCAAiC,iBACnC,KAAI,mBAAmB,WAAW,MAAM;AACtC,sBAAmB,QAAQ,IAAI;AAC/B,sBAAmB,UAAU;QAE7B,OAAM,IAAI,MACR,mGAED;IAIP,CAAC,6BAA6B,CAC/B;AAED,WAAU,SAAS,+CAA+C;AAChE,eAAa;AACX,OAAI,mBAAmB,WAAW,MAAM;AACtC,uBAAmB,QAAQ,IAAI;AAC/B,uBAAmB,UAAU;;;IAGhC,EAAE,CAAC;CACN,MAAM,SACH,iCAAiC,mBAC9B,+BACA,SACJ,eAAe,SACf,mBAAmB,UAAU;AAE/B,KAAI,SAAS,KACX,QAAO;EACE;EACP;EACD;AAgBH,OAAM,IAAI,MACR,+EACD"}
@@ -1,6 +1,4 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
1
  let react = require("react");
3
- react = require_rolldown_runtime.__toESM(react);
4
2
 
5
3
  //#region src/useHasCommittedRef.ts
6
4
  /**
@@ -1,11 +1,10 @@
1
1
  import { MutableRefObject } from "react";
2
2
 
3
3
  //#region src/useHasCommittedRef.d.ts
4
-
5
4
  /**
6
5
  * Returns true if the component has committed, false otherwise.
7
6
  */
8
7
  declare function useHasCommittedRef(): MutableRefObject<boolean>;
9
8
  //#endregion
10
9
  export { useHasCommittedRef };
11
- //# sourceMappingURL=useHasCommittedRef.d.ts.map
10
+ //# sourceMappingURL=useHasCommittedRef.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHasCommittedRef.d.cts","names":[],"sources":["../src/useHasCommittedRef.ts"],"mappings":";;;;;AAKA;iBAAgB,kBAAA,CAAA,GAAsB,gBAAA"}
@@ -1,7 +1,6 @@
1
1
  import { MutableRefObject } from "react";
2
2
 
3
3
  //#region src/useHasCommittedRef.d.ts
4
-
5
4
  /**
6
5
  * Returns true if the component has committed, false otherwise.
7
6
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useHasCommittedRef.d.mts","names":[],"sources":["../src/useHasCommittedRef.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;iBAAgB,kBAAA,CAAA,GAAsB"}
1
+ {"version":3,"file":"useHasCommittedRef.d.mts","names":[],"sources":["../src/useHasCommittedRef.ts"],"mappings":";;;;;AAKA;iBAAgB,kBAAA,CAAA,GAAsB,gBAAA"}
@@ -1,7 +1,7 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
- const require_useCachedResponsivePrecommitValue = require('./useCachedResponsivePrecommitValue.js');
1
+ 'use strict';
2
+
3
+ const require_useCachedResponsivePrecommitValue = require('./useCachedResponsivePrecommitValue.cjs');
3
4
  let react = require("react");
4
- react = require_rolldown_runtime.__toESM(react);
5
5
 
6
6
  //#region src/useLazyDisposableState.ts
7
7
  /**
@@ -1,8 +1,7 @@
1
- import { ParentCache } from "./ParentCache.js";
2
- import { UnassignedState } from "./useUpdatableDisposableState.js";
1
+ import { ParentCache } from "./ParentCache.cjs";
2
+ import { UnassignedState } from "./useUpdatableDisposableState.cjs";
3
3
 
4
4
  //#region src/useLazyDisposableState.d.ts
5
-
6
5
  /**
7
6
  * useLazyDisposableState<T>
8
7
  * - Takes a mutable parent cache and a factory function
@@ -17,4 +16,4 @@ declare function useLazyDisposableState<T>(parentCache: ParentCache<Exclude<T, U
17
16
  };
18
17
  //#endregion
19
18
  export { useLazyDisposableState };
20
- //# sourceMappingURL=useLazyDisposableState.d.ts.map
19
+ //# sourceMappingURL=useLazyDisposableState.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLazyDisposableState.d.cts","names":[],"sources":["../src/useLazyDisposableState.ts"],"mappings":";;;;;;AAiBA;;;;;;;iBAAgB,sBAAA,GAAA,CACd,WAAA,EAAa,WAAA,CAAY,OAAA,CAAQ,CAAA,EAAG,eAAA;EAEpC,KAAA,EAAO,CAAA;AAAA"}
@@ -2,7 +2,6 @@ import { ParentCache } from "./ParentCache.mjs";
2
2
  import { UnassignedState } from "./useUpdatableDisposableState.mjs";
3
3
 
4
4
  //#region src/useLazyDisposableState.d.ts
5
-
6
5
  /**
7
6
  * useLazyDisposableState<T>
8
7
  * - Takes a mutable parent cache and a factory function
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyDisposableState.d.mts","names":[],"sources":["../src/useLazyDisposableState.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;iBAAgB,uCACD,YAAY,QAAQ,GAAG;SAE7B"}
1
+ {"version":3,"file":"useLazyDisposableState.d.mts","names":[],"sources":["../src/useLazyDisposableState.ts"],"mappings":";;;;;;AAiBA;;;;;;;iBAAgB,sBAAA,GAAA,CACd,WAAA,EAAa,WAAA,CAAY,OAAA,CAAQ,CAAA,EAAG,eAAA;EAEpC,KAAA,EAAO,CAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyDisposableState.mjs","names":[],"sources":["../src/useLazyDisposableState.ts"],"sourcesContent":["'use strict';\n\nimport type { ItemCleanupPair } from '@isograph/isograph-disposable-types';\nimport { useEffect, useRef } from 'react';\nimport type { ParentCache } from './ParentCache';\nimport { useCachedResponsivePrecommitValue } from './useCachedResponsivePrecommitValue';\nimport { type UnassignedState } from './useUpdatableDisposableState';\n\n/**\n * useLazyDisposableState<T>\n * - Takes a mutable parent cache and a factory function\n * - Returns { state: T }\n *\n * This lazily loads the disposable item using useCachedResponsivePrecommitValue, then\n * (on commit) sets it in state. The item continues to be returned after\n * commit and is disposed when the hook unmounts.\n */\nexport function useLazyDisposableState<T>(\n parentCache: ParentCache<Exclude<T, UnassignedState>>,\n): {\n state: T;\n} {\n const itemCleanupPairRef = useRef<ItemCleanupPair<T> | null>(null);\n\n const preCommitItem = useCachedResponsivePrecommitValue(\n parentCache,\n (pair) => {\n itemCleanupPairRef.current?.[1]();\n itemCleanupPairRef.current = pair;\n },\n );\n\n useEffect(() => {\n return () => {\n const cleanupFn = itemCleanupPairRef.current?.[1];\n // TODO confirm useEffect is called in order.\n if (cleanupFn == null) {\n throw new Error(\n 'cleanupFn unexpectedly null. This indicates a bug in react-disposable-state.',\n );\n }\n return cleanupFn();\n };\n }, []);\n\n const returnedItem = preCommitItem?.state ?? itemCleanupPairRef.current?.[0];\n\n if (returnedItem != null) {\n return { state: returnedItem };\n }\n\n // Safety: This can't happen. For renders before the initial commit, preCommitItem\n // is non-null. During the initial commit, we assign itemCleanupPairRef.current,\n // so during subsequent renders, itemCleanupPairRef.current is non-null.\n throw new Error(\n 'returnedItem was unexpectedly null. This indicates a bug in react-disposable-state.',\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,SAAgB,uBACd,aAGA;CACA,MAAM,qBAAqB,OAAkC,KAAK;CAElE,MAAM,gBAAgB,kCACpB,cACC,SAAS;AACR,qBAAmB,UAAU,IAAI;AACjC,qBAAmB,UAAU;GAEhC;AAED,iBAAgB;AACd,eAAa;GACX,MAAM,YAAY,mBAAmB,UAAU;AAE/C,OAAI,aAAa,KACf,OAAM,IAAI,MACR,+EACD;AAEH,UAAO,WAAW;;IAEnB,EAAE,CAAC;CAEN,MAAM,eAAe,eAAe,SAAS,mBAAmB,UAAU;AAE1E,KAAI,gBAAgB,KAClB,QAAO,EAAE,OAAO,cAAc;AAMhC,OAAM,IAAI,MACR,sFACD"}
1
+ {"version":3,"file":"useLazyDisposableState.mjs","names":[],"sources":["../src/useLazyDisposableState.ts"],"sourcesContent":["'use strict';\n\nimport type { ItemCleanupPair } from '@isograph/disposable-types';\nimport { useEffect, useRef } from 'react';\nimport type { ParentCache } from './ParentCache';\nimport { useCachedResponsivePrecommitValue } from './useCachedResponsivePrecommitValue';\nimport { type UnassignedState } from './useUpdatableDisposableState';\n\n/**\n * useLazyDisposableState<T>\n * - Takes a mutable parent cache and a factory function\n * - Returns { state: T }\n *\n * This lazily loads the disposable item using useCachedResponsivePrecommitValue, then\n * (on commit) sets it in state. The item continues to be returned after\n * commit and is disposed when the hook unmounts.\n */\nexport function useLazyDisposableState<T>(\n parentCache: ParentCache<Exclude<T, UnassignedState>>,\n): {\n state: T;\n} {\n const itemCleanupPairRef = useRef<ItemCleanupPair<T> | null>(null);\n\n const preCommitItem = useCachedResponsivePrecommitValue(\n parentCache,\n (pair) => {\n itemCleanupPairRef.current?.[1]();\n itemCleanupPairRef.current = pair;\n },\n );\n\n useEffect(() => {\n return () => {\n const cleanupFn = itemCleanupPairRef.current?.[1];\n // TODO confirm useEffect is called in order.\n if (cleanupFn == null) {\n throw new Error(\n 'cleanupFn unexpectedly null. This indicates a bug in react-disposable-state.',\n );\n }\n return cleanupFn();\n };\n }, []);\n\n const returnedItem = preCommitItem?.state ?? itemCleanupPairRef.current?.[0];\n\n if (returnedItem != null) {\n return { state: returnedItem };\n }\n\n // Safety: This can't happen. For renders before the initial commit, preCommitItem\n // is non-null. During the initial commit, we assign itemCleanupPairRef.current,\n // so during subsequent renders, itemCleanupPairRef.current is non-null.\n throw new Error(\n 'returnedItem was unexpectedly null. This indicates a bug in react-disposable-state.',\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,SAAgB,uBACd,aAGA;CACA,MAAM,qBAAqB,OAAkC,KAAK;CAElE,MAAM,gBAAgB,kCACpB,cACC,SAAS;AACR,qBAAmB,UAAU,IAAI;AACjC,qBAAmB,UAAU;GAEhC;AAED,iBAAgB;AACd,eAAa;GACX,MAAM,YAAY,mBAAmB,UAAU;AAE/C,OAAI,aAAa,KACf,OAAM,IAAI,MACR,+EACD;AAEH,UAAO,WAAW;;IAEnB,EAAE,CAAC;CAEN,MAAM,eAAe,eAAe,SAAS,mBAAmB,UAAU;AAE1E,KAAI,gBAAgB,KAClB,QAAO,EAAE,OAAO,cAAc;AAMhC,OAAM,IAAI,MACR,sFACD"}
@@ -1,7 +1,5 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
- const require_useHasCommittedRef = require('./useHasCommittedRef.js');
1
+ const require_useHasCommittedRef = require('./useHasCommittedRef.cjs');
3
2
  let react = require("react");
4
- react = require_rolldown_runtime.__toESM(react);
5
3
 
6
4
  //#region src/useUpdatableDisposableState.ts
7
5
  const UNASSIGNED_STATE = Symbol();
@@ -40,4 +40,4 @@ type UseUpdatableDisposableStateReturnValue<T> = {
40
40
  declare function useUpdatableDisposableState<T = never>(): UseUpdatableDisposableStateReturnValue<T>;
41
41
  //#endregion
42
42
  export { UNASSIGNED_STATE, UnassignedState, useUpdatableDisposableState };
43
- //# sourceMappingURL=useUpdatableDisposableState.d.ts.map
43
+ //# sourceMappingURL=useUpdatableDisposableState.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUpdatableDisposableState.d.cts","names":[],"sources":["../src/useUpdatableDisposableState.ts"],"mappings":";;;cAIa,gBAAA;AAAA,KACD,eAAA,UAAyB,gBAAA;AAAA,KAEhC,sCAAA;EACH,KAAA,EAAO,CAAA,GAAI,eAAA;EACX,QAAA,GAAW,IAAA,EAAM,eAAA,CAAgB,OAAA,CAAQ,CAAA,EAAG,eAAA;AAAA;;AAJ9C;;;;;AAAsD;;;;;;;;;;;;;;;;;;;;;;;AAuDtD;iBAAgB,2BAAA,WAAA,CAAA,GAEX,sCAAA,CAAuC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useUpdatableDisposableState.d.mts","names":[],"sources":["../src/useUpdatableDisposableState.ts"],"sourcesContent":[],"mappings":";;;cAIa;KACD,eAAA,UAAyB;AADrC,KAGK,sCAHkD,CAAA,CAAA,CAAA,GAAA;EAC3C,KAAA,EAGH,CAHG,GAGC,eAHc;EAEtB,QAAA,EAAA,CAAA,IAAA,EAEc,eAFd,CAE8B,OAF9B,CAEsC,CAFA,EAEG,eAFH,CAAA,CAAA,EAAA,GAAA,IAAA;CAClC;;;;;;;AAoDT;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,0CAEX,uCAAuC"}
1
+ {"version":3,"file":"useUpdatableDisposableState.d.mts","names":[],"sources":["../src/useUpdatableDisposableState.ts"],"mappings":";;;cAIa,gBAAA;AAAA,KACD,eAAA,UAAyB,gBAAA;AAAA,KAEhC,sCAAA;EACH,KAAA,EAAO,CAAA,GAAI,eAAA;EACX,QAAA,GAAW,IAAA,EAAM,eAAA,CAAgB,OAAA,CAAQ,CAAA,EAAG,eAAA;AAAA;;AAJ9C;;;;;AAAsD;;;;;;;;;;;;;;;;;;;;;;;AAuDtD;iBAAgB,2BAAA,WAAA,CAAA,GAEX,sCAAA,CAAuC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useUpdatableDisposableState.mjs","names":["UNASSIGNED_STATE: unique symbol","ici: ICI<T>"],"sources":["../src/useUpdatableDisposableState.ts"],"sourcesContent":["import type { ItemCleanupPair } from '@isograph/disposable-types';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useHasCommittedRef } from './useHasCommittedRef';\n\nexport const UNASSIGNED_STATE: unique symbol = Symbol();\nexport type UnassignedState = typeof UNASSIGNED_STATE;\n\ntype UseUpdatableDisposableStateReturnValue<T> = {\n state: T | UnassignedState;\n setState: (pair: ItemCleanupPair<Exclude<T, UnassignedState>>) => void;\n};\n\n/**\n * ICI stands for ItemCleanupIndex. Use a short name because it shows up a lot.\n *\n * Like an ItemCleanupPair<T>, but with an additional index and as a struct\n * for readability.\n *\n * Interally, we must keep track of the index of the state change. The disposable\n * items that are set in state are not guaranteed to be distinct according to ===,\n * as in `setState([1, dispose1]); setState([1, dispose2])`. Following this, we\n * would expect dispose1 to be called on commit. If state items were compared for\n * ===, then dispose1 would not be called in such a situation.\n *\n * Note that this comes at a runtime cost, and we may want to expose APIs that do\n * not incur this runtime cost, for example in cases where every disposable item is\n * distinguishable via ===.\n */\ntype ICI<T> = { item: T; cleanup: () => void; index: number };\n\n/**\n * useUpdatableDisposableState\n * - Returns a { state, setItem } object.\n * - setItem accepts an ItemCleanupPair<T>, and throws if called before commit.\n * - setItem sets the T in state and adds it to a set.\n * - React's behavior is that when the hook commits, whatever item is currently\n * returned from the useState hook is the oldest item which will ever be returned\n * from that useState hook. (More newly created ones can later be returned with\n * concurrent mode.)\n * - When this hook commits, all items up to, but not including, the item currently\n * returned from the useState hook are disposed and removed from the set.\n *\n * Calling setState before the hook commits:\n * - Calling setState before the hook commits is disallowed because until the hook\n * commits, React will not schedule any unmount callbacks, meaning that if this\n * hook never commits, any disposable items passed to setState will never be\n * disposed.\n * - We also cannot store them in some cache, because multiple components can share\n * the same cache location (for example, if they are loading the same query from\n * multiple components), so updating the cache with the disposable item will cause\n * both components to show the updated data, which is almost certainly a bug.\n * - Note that calling setState before commit is probably an anti-pattern! Consider\n * not doing it.\n * - If you must, the workaround is to lazily load the disposable item with\n * useDisposableState or useLazyDisposableState, and update the cache location\n * instead of calling setState before commit. One can update the cache location\n * by calling setState on some parent component that has already mounted, and\n * therefore passing in different props.\n * - This may only work in concurrent mode, though.\n */\nexport function useUpdatableDisposableState<\n T = never,\n>(): UseUpdatableDisposableStateReturnValue<T> {\n const hasCommittedRef = useHasCommittedRef();\n\n const undisposedICIs = useRef(new Set<ICI<T>>());\n const setStateCountRef = useRef(0);\n\n const [stateICI, setStateICI] = useState<ICI<T> | UnassignedState>(\n UNASSIGNED_STATE,\n );\n\n const setStateAfterCommit = useCallback(\n (itemCleanupPair: ItemCleanupPair<T>) => {\n if (!hasCommittedRef.current) {\n throw new Error(\n 'Calling setState before the component has committed is unsafe and disallowed.',\n );\n }\n\n const ici: ICI<T> = {\n item: itemCleanupPair[0],\n cleanup: itemCleanupPair[1],\n index: setStateCountRef.current,\n };\n setStateCountRef.current++;\n undisposedICIs.current.add(ici);\n setStateICI(ici);\n },\n [setStateICI],\n );\n\n useEffect(function cleanupUnreachableItems() {\n const indexInState = stateICI !== UNASSIGNED_STATE ? stateICI.index : 0;\n\n if (indexInState === 0) {\n return;\n }\n\n for (const undisposedICI of undisposedICIs.current) {\n if (undisposedICI.index === indexInState) {\n break;\n }\n undisposedICIs.current.delete(undisposedICI);\n undisposedICI.cleanup();\n }\n });\n\n useEffect(() => {\n return function disposeAllRemainingItems() {\n for (const undisposedICI of undisposedICIs.current) {\n undisposedICI.cleanup();\n }\n };\n }, []);\n\n return {\n setState: setStateAfterCommit,\n state: stateICI !== UNASSIGNED_STATE ? stateICI.item : UNASSIGNED_STATE,\n };\n}\n\n// @ts-ignore\nfunction tsTests() {\n const a = useUpdatableDisposableState();\n // @ts-expect-error\n a.setState([UNASSIGNED_STATE, () => {}]);\n // @ts-expect-error\n a.setState(['asdf', () => {}]);\n const b = useUpdatableDisposableState<string | UnassignedState>();\n // @ts-expect-error\n b.setState([UNASSIGNED_STATE, () => {}]);\n b.setState(['asdf', () => {}]);\n}\n"],"mappings":";;;;AAIA,MAAaA,mBAAkC,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDvD,SAAgB,8BAE+B;CAC7C,MAAM,kBAAkB,oBAAoB;CAE5C,MAAM,iBAAiB,uBAAO,IAAI,KAAa,CAAC;CAChD,MAAM,mBAAmB,OAAO,EAAE;CAElC,MAAM,CAAC,UAAU,eAAe,SAC9B,iBACD;CAED,MAAM,sBAAsB,aACzB,oBAAwC;AACvC,MAAI,CAAC,gBAAgB,QACnB,OAAM,IAAI,MACR,gFACD;EAGH,MAAMC,MAAc;GAClB,MAAM,gBAAgB;GACtB,SAAS,gBAAgB;GACzB,OAAO,iBAAiB;GACzB;AACD,mBAAiB;AACjB,iBAAe,QAAQ,IAAI,IAAI;AAC/B,cAAY,IAAI;IAElB,CAAC,YAAY,CACd;AAED,WAAU,SAAS,0BAA0B;EAC3C,MAAM,eAAe,aAAa,mBAAmB,SAAS,QAAQ;AAEtE,MAAI,iBAAiB,EACnB;AAGF,OAAK,MAAM,iBAAiB,eAAe,SAAS;AAClD,OAAI,cAAc,UAAU,aAC1B;AAEF,kBAAe,QAAQ,OAAO,cAAc;AAC5C,iBAAc,SAAS;;GAEzB;AAEF,iBAAgB;AACd,SAAO,SAAS,2BAA2B;AACzC,QAAK,MAAM,iBAAiB,eAAe,QACzC,eAAc,SAAS;;IAG1B,EAAE,CAAC;AAEN,QAAO;EACL,UAAU;EACV,OAAO,aAAa,mBAAmB,SAAS,OAAO;EACxD"}
1
+ {"version":3,"file":"useUpdatableDisposableState.mjs","names":[],"sources":["../src/useUpdatableDisposableState.ts"],"sourcesContent":["import type { ItemCleanupPair } from '@isograph/disposable-types';\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { useHasCommittedRef } from './useHasCommittedRef';\n\nexport const UNASSIGNED_STATE: unique symbol = Symbol();\nexport type UnassignedState = typeof UNASSIGNED_STATE;\n\ntype UseUpdatableDisposableStateReturnValue<T> = {\n state: T | UnassignedState;\n setState: (pair: ItemCleanupPair<Exclude<T, UnassignedState>>) => void;\n};\n\n/**\n * ICI stands for ItemCleanupIndex. Use a short name because it shows up a lot.\n *\n * Like an ItemCleanupPair<T>, but with an additional index and as a struct\n * for readability.\n *\n * Interally, we must keep track of the index of the state change. The disposable\n * items that are set in state are not guaranteed to be distinct according to ===,\n * as in `setState([1, dispose1]); setState([1, dispose2])`. Following this, we\n * would expect dispose1 to be called on commit. If state items were compared for\n * ===, then dispose1 would not be called in such a situation.\n *\n * Note that this comes at a runtime cost, and we may want to expose APIs that do\n * not incur this runtime cost, for example in cases where every disposable item is\n * distinguishable via ===.\n */\ntype ICI<T> = { item: T; cleanup: () => void; index: number };\n\n/**\n * useUpdatableDisposableState\n * - Returns a { state, setItem } object.\n * - setItem accepts an ItemCleanupPair<T>, and throws if called before commit.\n * - setItem sets the T in state and adds it to a set.\n * - React's behavior is that when the hook commits, whatever item is currently\n * returned from the useState hook is the oldest item which will ever be returned\n * from that useState hook. (More newly created ones can later be returned with\n * concurrent mode.)\n * - When this hook commits, all items up to, but not including, the item currently\n * returned from the useState hook are disposed and removed from the set.\n *\n * Calling setState before the hook commits:\n * - Calling setState before the hook commits is disallowed because until the hook\n * commits, React will not schedule any unmount callbacks, meaning that if this\n * hook never commits, any disposable items passed to setState will never be\n * disposed.\n * - We also cannot store them in some cache, because multiple components can share\n * the same cache location (for example, if they are loading the same query from\n * multiple components), so updating the cache with the disposable item will cause\n * both components to show the updated data, which is almost certainly a bug.\n * - Note that calling setState before commit is probably an anti-pattern! Consider\n * not doing it.\n * - If you must, the workaround is to lazily load the disposable item with\n * useDisposableState or useLazyDisposableState, and update the cache location\n * instead of calling setState before commit. One can update the cache location\n * by calling setState on some parent component that has already mounted, and\n * therefore passing in different props.\n * - This may only work in concurrent mode, though.\n */\nexport function useUpdatableDisposableState<\n T = never,\n>(): UseUpdatableDisposableStateReturnValue<T> {\n const hasCommittedRef = useHasCommittedRef();\n\n const undisposedICIs = useRef(new Set<ICI<T>>());\n const setStateCountRef = useRef(0);\n\n const [stateICI, setStateICI] = useState<ICI<T> | UnassignedState>(\n UNASSIGNED_STATE,\n );\n\n const setStateAfterCommit = useCallback(\n (itemCleanupPair: ItemCleanupPair<T>) => {\n if (!hasCommittedRef.current) {\n throw new Error(\n 'Calling setState before the component has committed is unsafe and disallowed.',\n );\n }\n\n const ici: ICI<T> = {\n item: itemCleanupPair[0],\n cleanup: itemCleanupPair[1],\n index: setStateCountRef.current,\n };\n setStateCountRef.current++;\n undisposedICIs.current.add(ici);\n setStateICI(ici);\n },\n [setStateICI],\n );\n\n useEffect(function cleanupUnreachableItems() {\n const indexInState = stateICI !== UNASSIGNED_STATE ? stateICI.index : 0;\n\n if (indexInState === 0) {\n return;\n }\n\n for (const undisposedICI of undisposedICIs.current) {\n if (undisposedICI.index === indexInState) {\n break;\n }\n undisposedICIs.current.delete(undisposedICI);\n undisposedICI.cleanup();\n }\n });\n\n useEffect(() => {\n return function disposeAllRemainingItems() {\n for (const undisposedICI of undisposedICIs.current) {\n undisposedICI.cleanup();\n }\n };\n }, []);\n\n return {\n setState: setStateAfterCommit,\n state: stateICI !== UNASSIGNED_STATE ? stateICI.item : UNASSIGNED_STATE,\n };\n}\n\n// @ts-ignore\nfunction tsTests() {\n const a = useUpdatableDisposableState();\n // @ts-expect-error\n a.setState([UNASSIGNED_STATE, () => {}]);\n // @ts-expect-error\n a.setState(['asdf', () => {}]);\n const b = useUpdatableDisposableState<string | UnassignedState>();\n // @ts-expect-error\n b.setState([UNASSIGNED_STATE, () => {}]);\n b.setState(['asdf', () => {}]);\n}\n"],"mappings":";;;;AAIA,MAAa,mBAAkC,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDvD,SAAgB,8BAE+B;CAC7C,MAAM,kBAAkB,oBAAoB;CAE5C,MAAM,iBAAiB,uBAAO,IAAI,KAAa,CAAC;CAChD,MAAM,mBAAmB,OAAO,EAAE;CAElC,MAAM,CAAC,UAAU,eAAe,SAC9B,iBACD;CAED,MAAM,sBAAsB,aACzB,oBAAwC;AACvC,MAAI,CAAC,gBAAgB,QACnB,OAAM,IAAI,MACR,gFACD;EAGH,MAAM,MAAc;GAClB,MAAM,gBAAgB;GACtB,SAAS,gBAAgB;GACzB,OAAO,iBAAiB;GACzB;AACD,mBAAiB;AACjB,iBAAe,QAAQ,IAAI,IAAI;AAC/B,cAAY,IAAI;IAElB,CAAC,YAAY,CACd;AAED,WAAU,SAAS,0BAA0B;EAC3C,MAAM,eAAe,aAAa,mBAAmB,SAAS,QAAQ;AAEtE,MAAI,iBAAiB,EACnB;AAGF,OAAK,MAAM,iBAAiB,eAAe,SAAS;AAClD,OAAI,cAAc,UAAU,aAC1B;AAEF,kBAAe,QAAQ,OAAO,cAAc;AAC5C,iBAAc,SAAS;;GAEzB;AAEF,iBAAgB;AACd,SAAO,SAAS,2BAA2B;AACzC,QAAK,MAAM,iBAAiB,eAAe,QACzC,eAAc,SAAS;;IAG1B,EAAE,CAAC;AAEN,QAAO;EACL,UAAU;EACV,OAAO,aAAa,mBAAmB,SAAS,OAAO;EACxD"}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@isograph/react-disposable-state",
3
- "version": "0.0.0-main-a840a70e",
3
+ "version": "0.0.0-main-c09c9dbf",
4
4
  "description": "Primitives for managing disposable state in React",
5
5
  "homepage": "https://isograph.dev",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
6
+ "main": "./dist/index.cjs",
7
+ "types": "./dist/index.d.cts",
8
8
  "author": "Isograph Labs",
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
- "@isograph/disposable-types": "0.0.0-main-a840a70e"
11
+ "@isograph/disposable-types": "0.0.0-main-c09c9dbf"
12
12
  },
13
13
  "peerDependencies": {
14
14
  "react": "^18.0.0 || ^19.0.0"
@@ -27,8 +27,8 @@
27
27
  "module": "./dist/index.mjs",
28
28
  "exports": {
29
29
  ".": {
30
- "import": "./dist/index.mjs",
31
- "require": "./dist/index.js"
30
+ "require": "./dist/index.cjs",
31
+ "import": "./dist/index.mjs"
32
32
  },
33
33
  "./package.json": "./package.json"
34
34
  },
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import type { ItemCleanupPair } from '@isograph/isograph-disposable-types';
3
+ import type { ItemCleanupPair } from '@isograph/disposable-types';
4
4
  import { useEffect, useRef } from 'react';
5
5
  import type { ParentCache } from './ParentCache';
6
6
  import { useCachedResponsivePrecommitValue } from './useCachedResponsivePrecommitValue';
package/tsconfig.json CHANGED
@@ -1,6 +1,4 @@
1
1
  {
2
- "extends": "./tsconfig.pkg.json",
3
- "compilerOptions": {
4
- "noEmit": true
5
- }
2
+ "extends": "../../tsconfig.build.json",
3
+ "include": ["./**/*.ts"]
6
4
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"CacheItem.d.ts","names":[],"sources":["../src/CacheItem.ts"],"sourcesContent":[],"mappings":";;;KAQY,2BAAA;;AAAZ,CAAA;AAGY,KAAA,8BAA8B,CAAA,CAAA,CAAA,GAAA;EAQ9B,IAAA,EAAA,gCAA2B;EAa3B,KAAA,EAnBH,CAmBG;EACoB,YAAA,EAAA,GAAA,GAAA,IAAA;EAA5B,oBAAA,EAAA,MAAA;CAC+B;AAA/B,KAfQ,2BAeR,CAAA,CAAA,CAAA,GAAA;EACA,IAAA,EAAA,6BAAA;EAA2B,KAAA,EAdtB,CAcsB;EAEnB,YAAA,EAAA,GAAA,GAAgB,IAAA;EA+Bf,qBAAS,EAAA,GAAA,GAAA,IAAA;EAUD,oBAAA,EAAA,MAAA;EAAR,oBAAA,EAAA,MAAA;CACc;AACd,KAhDD,cAgDC,CAAA,CAAA,CAAA,GA/CT,2BA+CS,CA/CmB,CA+CnB,CAAA,GA9CT,8BA8CS,CA9CsB,CA8CtB,CAAA,GA7CT,2BA6CS;AAgBC,KA3DF,gBAAA,GA2DE;EAkBgB,mBAAA,EAAA,MAAA;CACT;;;;;AAyPrB;;;;;;;;;;;;;;;;;;;;cAxSa;;;uBAUA,QAAQ,2BACM,oBACd;cAgBC;yDAkBgB,YACzB,gBAAgB;qBA+EA;qBAqEA;;;;iBAqGL,+CACL,QAAQ,2BACM,oBACd,2BACP,UAAU,IAAI"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ParentCache.d.ts","names":[],"sources":["../src/ParentCache.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2BA;;;;;;;;;;;;;;cAAa;;;uBAMU,QAAQ;;;;;;;;;;;oCAcK,gBAAgB;sCAMd,UAAU,IAAI,GAAG;;;iBAsCtC,QAAQ"}
@@ -1,25 +0,0 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
-
25
- exports.__toESM = __toESM;
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCachedResponsivePrecommitValue.d.ts","names":[],"sources":["../src/useCachedResponsivePrecommitValue.ts"],"sourcesContent":[],"mappings":";;;;;;;AAsCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,kDACD,YAAY,qBACR,gBAAgB;SACvB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDisposableState.d.ts","names":[],"sources":["../src/useDisposableState.ts"],"sourcesContent":[],"mappings":";;;;;KAUK;SACI;EADJ,QAAA,EAAA,CAAA,IAAA,EAEc,eAFd,CAE8B,OAF9B,CAEsC,CAFA,EAEG,eAFH,CAAA,CAAA,EAAA,GAAA,IAAA;CAClC;AACkC,iBAG3B,kBAH2B,CAAA,IAAA,KAAA,CAAA,CAAA,WAAA,EAI5B,WAJ4B,CAIhB,CAJgB,CAAA,CAAA,EAKxC,sCALwC,CAKD,CALC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHasCommittedRef.d.ts","names":[],"sources":["../src/useHasCommittedRef.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;iBAAgB,kBAAA,CAAA,GAAsB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLazyDisposableState.d.ts","names":[],"sources":["../src/useLazyDisposableState.ts"],"sourcesContent":[],"mappings":";;;;;;;AAiBA;;;;;;;iBAAgB,uCACD,YAAY,QAAQ,GAAG;SAE7B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useUpdatableDisposableState.d.ts","names":[],"sources":["../src/useUpdatableDisposableState.ts"],"sourcesContent":[],"mappings":";;;cAIa;KACD,eAAA,UAAyB;AADrC,KAGK,sCAHkD,CAAA,CAAA,CAAA,GAAA;EAC3C,KAAA,EAGH,CAHG,GAGC,eAHc;EAEtB,QAAA,EAAA,CAAA,IAAA,EAEc,eAFd,CAE8B,OAF9B,CAEsC,CAFA,EAEG,eAFH,CAAA,CAAA,EAAA,GAAA,IAAA;CAClC;;;;;;;AAoDT;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,0CAEX,uCAAuC"}
package/tsconfig.pkg.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.build.json",
3
- "compilerOptions": {
4
- "outDir": "./dist/",
5
- "rootDir": "./src/",
6
- "declaration": true
7
- },
8
- "include": ["./**/*.ts"]
9
- }
File without changes