@isograph/react-disposable-state 0.0.0-main-c09c9dbf → 0.0.0-main-ae4fea0e
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.
- package/.turbo/turbo-compile-libs.log +3 -3
- package/.turbo/turbo-tsc.log +2 -2
- package/dist/ParentCache.cjs +3 -2
- package/dist/ParentCache.d.cts +3 -2
- package/dist/ParentCache.d.cts.map +1 -1
- package/dist/ParentCache.d.mts +3 -2
- package/dist/ParentCache.d.mts.map +1 -1
- package/dist/ParentCache.mjs +3 -2
- package/dist/ParentCache.mjs.map +1 -1
- package/package.json +2 -2
- package/src/ParentCache.ts +26 -21
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
../.. | WARN Unsupported engine: wanted: {"node":"24.12.0"} (current: {"node":"
|
|
1
|
+
../.. | WARN Unsupported engine: wanted: {"node":"24.12.0"} (current: {"node":"v24.20.0","pnpm":"10.15.0"})
|
|
2
2
|
|
|
3
|
-
> @isograph/react-disposable-state@0.0.0-main-
|
|
3
|
+
> @isograph/react-disposable-state@0.0.0-main-ae4fea0e compile-libs /home/runner/work/isograph/isograph/libs/isograph-react-disposable-state
|
|
4
4
|
> tsdown
|
|
5
5
|
|
|
6
6
|
[34mℹ[39m tsdown [2mv0.20.1[22m powered by rolldown [2mv1.0.0-rc.1[22m
|
|
7
7
|
[34mℹ[39m config file: [4m/home/runner/work/isograph/isograph/tsdown.config.ts[24m
|
|
8
|
-
(node:
|
|
8
|
+
(node:2799) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/isograph/isograph/tsdown.config.ts?no-cache=faf0b459-e85c-4dab-8fb5-f265432db97d 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)
|
package/.turbo/turbo-tsc.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
../.. | WARN Unsupported engine: wanted: {"node":"24.12.0"} (current: {"node":"
|
|
1
|
+
../.. | WARN Unsupported engine: wanted: {"node":"24.12.0"} (current: {"node":"v24.20.0","pnpm":"10.15.0"})
|
|
2
2
|
|
|
3
|
-
> @isograph/react-disposable-state@0.0.0-main-
|
|
3
|
+
> @isograph/react-disposable-state@0.0.0-main-ae4fea0e tsc /home/runner/work/isograph/isograph/libs/isograph-react-disposable-state
|
|
4
4
|
> tsc
|
|
5
5
|
|
package/dist/ParentCache.cjs
CHANGED
|
@@ -18,9 +18,10 @@ const require_CacheItem = require('./CacheItem.cjs');
|
|
|
18
18
|
* be called
|
|
19
19
|
*/
|
|
20
20
|
var ParentCache = class {
|
|
21
|
-
constructor(factory) {
|
|
21
|
+
constructor(factory, options) {
|
|
22
22
|
this.__cacheItem = null;
|
|
23
23
|
this.__factory = factory;
|
|
24
|
+
this.__options = options;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* This is called from useCachedResponsivePrecommitValue, when the parent cache is populated
|
|
@@ -41,7 +42,7 @@ var ParentCache = class {
|
|
|
41
42
|
__populateAndTemporaryRetain() {
|
|
42
43
|
const pair = require_CacheItem.createTemporarilyRetainedCacheItem(this.__factory, () => {
|
|
43
44
|
if (this.__cacheItem === pair[0]) this.empty();
|
|
44
|
-
});
|
|
45
|
+
}, this.__options);
|
|
45
46
|
const [cacheItem, disposeTemporaryRetain] = pair;
|
|
46
47
|
this.__cacheItem = cacheItem;
|
|
47
48
|
return [
|
package/dist/ParentCache.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CacheItem } from "./CacheItem.cjs";
|
|
1
|
+
import { CacheItem, CacheItemOptions } from "./CacheItem.cjs";
|
|
2
2
|
import { CleanupFn, Factory, ItemCleanupPair } from "@isograph/disposable-types";
|
|
3
3
|
|
|
4
4
|
//#region src/ParentCache.d.ts
|
|
@@ -21,7 +21,8 @@ import { CleanupFn, Factory, ItemCleanupPair } from "@isograph/disposable-types"
|
|
|
21
21
|
declare class ParentCache<T> {
|
|
22
22
|
private __cacheItem;
|
|
23
23
|
private readonly __factory;
|
|
24
|
-
|
|
24
|
+
private readonly __options;
|
|
25
|
+
constructor(factory: Factory<T>, options?: CacheItemOptions);
|
|
25
26
|
/**
|
|
26
27
|
* This is called from useCachedResponsivePrecommitValue, when the parent cache is populated
|
|
27
28
|
* and a previous temporary retain has been disposed. This can occur in scenarios like:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParentCache.d.cts","names":[],"sources":["../src/ParentCache.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ParentCache.d.cts","names":[],"sources":["../src/ParentCache.ts"],"mappings":";;;;;;AA0BA;;;;;;;;;;;;;;cAAa,WAAA;EAAA,QACH,WAAA;EAAA,iBACS,SAAA;EAAA,iBACA,SAAA;cAIL,OAAA,EAAS,OAAA,CAAQ,CAAA,GAAI,OAAA,GAAU,gBAAA;EAJ1B;;;;;;;;;;EAmBjB,8BAAA,CAAA,GAAkC,eAAA,CAAgB,CAAA;EAMlD,+BAAA,CAAA,IAAoC,SAAA,CAAU,CAAA,GAAI,CAAA,EAAG,SAAA;EAAA,QAM7C,4BAAA;EAgCR,KAAA,CAAA;EAAA,IAII,OAAA,CAAA,GAAW,OAAA,CAAQ,CAAA;EAIvB,OAAA,CAAA;AAAA"}
|
package/dist/ParentCache.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CacheItem } from "./CacheItem.mjs";
|
|
1
|
+
import { CacheItem, CacheItemOptions } from "./CacheItem.mjs";
|
|
2
2
|
import { CleanupFn, Factory, ItemCleanupPair } from "@isograph/disposable-types";
|
|
3
3
|
|
|
4
4
|
//#region src/ParentCache.d.ts
|
|
@@ -21,7 +21,8 @@ import { CleanupFn, Factory, ItemCleanupPair } from "@isograph/disposable-types"
|
|
|
21
21
|
declare class ParentCache<T> {
|
|
22
22
|
private __cacheItem;
|
|
23
23
|
private readonly __factory;
|
|
24
|
-
|
|
24
|
+
private readonly __options;
|
|
25
|
+
constructor(factory: Factory<T>, options?: CacheItemOptions);
|
|
25
26
|
/**
|
|
26
27
|
* This is called from useCachedResponsivePrecommitValue, when the parent cache is populated
|
|
27
28
|
* and a previous temporary retain has been disposed. This can occur in scenarios like:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParentCache.d.mts","names":[],"sources":["../src/ParentCache.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ParentCache.d.mts","names":[],"sources":["../src/ParentCache.ts"],"mappings":";;;;;;AA0BA;;;;;;;;;;;;;;cAAa,WAAA;EAAA,QACH,WAAA;EAAA,iBACS,SAAA;EAAA,iBACA,SAAA;cAIL,OAAA,EAAS,OAAA,CAAQ,CAAA,GAAI,OAAA,GAAU,gBAAA;EAJ1B;;;;;;;;;;EAmBjB,8BAAA,CAAA,GAAkC,eAAA,CAAgB,CAAA;EAMlD,+BAAA,CAAA,IAAoC,SAAA,CAAU,CAAA,GAAI,CAAA,EAAG,SAAA;EAAA,QAM7C,4BAAA;EAgCR,KAAA,CAAA;EAAA,IAII,OAAA,CAAA,GAAW,OAAA,CAAQ,CAAA;EAIvB,OAAA,CAAA;AAAA"}
|
package/dist/ParentCache.mjs
CHANGED
|
@@ -18,9 +18,10 @@ import { createTemporarilyRetainedCacheItem } from "./CacheItem.mjs";
|
|
|
18
18
|
* be called
|
|
19
19
|
*/
|
|
20
20
|
var ParentCache = class {
|
|
21
|
-
constructor(factory) {
|
|
21
|
+
constructor(factory, options) {
|
|
22
22
|
this.__cacheItem = null;
|
|
23
23
|
this.__factory = factory;
|
|
24
|
+
this.__options = options;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* This is called from useCachedResponsivePrecommitValue, when the parent cache is populated
|
|
@@ -41,7 +42,7 @@ var ParentCache = class {
|
|
|
41
42
|
__populateAndTemporaryRetain() {
|
|
42
43
|
const pair = createTemporarilyRetainedCacheItem(this.__factory, () => {
|
|
43
44
|
if (this.__cacheItem === pair[0]) this.empty();
|
|
44
|
-
});
|
|
45
|
+
}, this.__options);
|
|
45
46
|
const [cacheItem, disposeTemporaryRetain] = pair;
|
|
46
47
|
this.__cacheItem = cacheItem;
|
|
47
48
|
return [
|
package/dist/ParentCache.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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, CacheItemOptions } from './CacheItem';\nimport { createTemporarilyRetainedCacheItem } from './CacheItem';\n\n// TODO convert cache impl to a getter and setter and free functions\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 private readonly __options: CacheItemOptions | void;\n\n // TODO pass an onEmpty function, which can e.g. remove this ParentCache\n // from some parent object.\n constructor(factory: Factory<T>, options?: CacheItemOptions) {\n this.__factory = factory;\n this.__options = options;\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(\n this.__factory,\n () => {\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 this.__options,\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":";;;;;;;;;;;;;;;;;;;AA0BA,IAAa,cAAb,MAA4B;CAO1B,YAAY,SAAqB,SAA4B;qBANlB;AAOzC,OAAK,YAAY;AACjB,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,mCACE,KAAK,iBACC;AAcJ,OAAI,KAAK,gBAAgB,KAAK,GAC5B,MAAK,OAAO;KAGhB,KAAK,UACN;EAIH,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isograph/react-disposable-state",
|
|
3
|
-
"version": "0.0.0-main-
|
|
3
|
+
"version": "0.0.0-main-ae4fea0e",
|
|
4
4
|
"description": "Primitives for managing disposable state in React",
|
|
5
5
|
"homepage": "https://isograph.dev",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"author": "Isograph Labs",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@isograph/disposable-types": "0.0.0-main-
|
|
11
|
+
"@isograph/disposable-types": "0.0.0-main-ae4fea0e"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"react": "^18.0.0 || ^19.0.0"
|
package/src/ParentCache.ts
CHANGED
|
@@ -3,11 +3,10 @@ import type {
|
|
|
3
3
|
Factory,
|
|
4
4
|
ItemCleanupPair,
|
|
5
5
|
} from '@isograph/disposable-types';
|
|
6
|
-
import type { CacheItem } from './CacheItem';
|
|
6
|
+
import type { CacheItem, CacheItemOptions } from './CacheItem';
|
|
7
7
|
import { createTemporarilyRetainedCacheItem } from './CacheItem';
|
|
8
8
|
|
|
9
9
|
// TODO convert cache impl to a getter and setter and free functions
|
|
10
|
-
// TODO accept options that get passed to CacheItem
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* ParentCache
|
|
@@ -28,11 +27,13 @@ import { createTemporarilyRetainedCacheItem } from './CacheItem';
|
|
|
28
27
|
export class ParentCache<T> {
|
|
29
28
|
private __cacheItem: CacheItem<T> | null = null;
|
|
30
29
|
private readonly __factory: Factory<T>;
|
|
30
|
+
private readonly __options: CacheItemOptions | void;
|
|
31
31
|
|
|
32
32
|
// TODO pass an onEmpty function, which can e.g. remove this ParentCache
|
|
33
33
|
// from some parent object.
|
|
34
|
-
constructor(factory: Factory<T
|
|
34
|
+
constructor(factory: Factory<T>, options?: CacheItemOptions) {
|
|
35
35
|
this.__factory = factory;
|
|
36
|
+
this.__options = options;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -59,24 +60,28 @@ export class ParentCache<T> {
|
|
|
59
60
|
|
|
60
61
|
private __populateAndTemporaryRetain(): [CacheItem<T>, T, CleanupFn] {
|
|
61
62
|
const pair: ItemCleanupPair<CacheItem<T>> =
|
|
62
|
-
createTemporarilyRetainedCacheItem(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
createTemporarilyRetainedCacheItem(
|
|
64
|
+
this.__factory,
|
|
65
|
+
() => {
|
|
66
|
+
// We are doing this check because we don't want to remove the cache item
|
|
67
|
+
// if it is not the one that was created when the temporary retain was created.
|
|
68
|
+
//
|
|
69
|
+
// Consider the following scenario:
|
|
70
|
+
// - we populate the cache with CacheItem A,
|
|
71
|
+
// - then manually delete CacheItem A (e.g. to force a refetch)
|
|
72
|
+
// - then, we re-populate the parent cache with CacheItem B
|
|
73
|
+
// - then, the temporary retain of CacheItem A is disposed or expires.
|
|
74
|
+
//
|
|
75
|
+
// At this point, we don't want to delete CacheItem B from the cache.
|
|
76
|
+
//
|
|
77
|
+
// TODO consider what happens if items are === comparable to each other,
|
|
78
|
+
// e.g. the item is a number!
|
|
79
|
+
if (this.__cacheItem === pair[0]) {
|
|
80
|
+
this.empty();
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
this.__options,
|
|
84
|
+
);
|
|
80
85
|
|
|
81
86
|
// We deconstruct this here instead of at the definition site because otherwise,
|
|
82
87
|
// typescript thinks that cacheItem is any, because it's referenced in the closure.
|