@isograph/react-disposable-state 0.5.0 → 0.5.1
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 +9 -2
- package/dist/CacheItem.d.mts +63 -0
- package/dist/CacheItem.d.mts.map +1 -0
- package/dist/CacheItem.d.ts +33 -29
- package/dist/CacheItem.d.ts.map +1 -1
- package/dist/CacheItem.js +191 -266
- package/dist/CacheItem.mjs +193 -0
- package/dist/CacheItem.mjs.map +1 -0
- package/dist/ParentCache.d.mts +45 -0
- package/dist/ParentCache.d.mts.map +1 -0
- package/dist/ParentCache.d.ts +27 -22
- package/dist/ParentCache.d.ts.map +1 -1
- package/dist/ParentCache.js +69 -85
- package/dist/ParentCache.mjs +73 -0
- package/dist/ParentCache.mjs.map +1 -0
- package/dist/_virtual/rolldown_runtime.js +25 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.js +24 -24
- package/dist/index.mjs +11 -0
- package/dist/useCachedResponsivePrecommitValue.d.mts +43 -0
- package/dist/useCachedResponsivePrecommitValue.d.mts.map +1 -0
- package/dist/useCachedResponsivePrecommitValue.d.ts +9 -4
- package/dist/useCachedResponsivePrecommitValue.d.ts.map +1 -1
- package/dist/useCachedResponsivePrecommitValue.js +55 -90
- package/dist/useCachedResponsivePrecommitValue.mjs +57 -0
- package/dist/useCachedResponsivePrecommitValue.mjs.map +1 -0
- package/dist/useDisposableState.d.mts +13 -0
- package/dist/useDisposableState.d.mts.map +1 -0
- package/dist/useDisposableState.d.ts +10 -7
- package/dist/useDisposableState.d.ts.map +1 -1
- package/dist/useDisposableState.js +36 -69
- package/dist/useDisposableState.mjs +37 -0
- package/dist/useDisposableState.mjs.map +1 -0
- package/dist/useHasCommittedRef.d.mts +11 -0
- package/dist/useHasCommittedRef.d.mts.map +1 -0
- package/dist/useHasCommittedRef.d.ts +7 -2
- package/dist/useHasCommittedRef.d.ts.map +1 -1
- package/dist/useHasCommittedRef.js +15 -11
- package/dist/useHasCommittedRef.mjs +17 -0
- package/dist/useHasCommittedRef.mjs.map +1 -0
- package/dist/useLazyDisposableState.d.mts +20 -0
- package/dist/useLazyDisposableState.d.mts.map +1 -0
- package/dist/useLazyDisposableState.d.ts +9 -4
- package/dist/useLazyDisposableState.d.ts.map +1 -1
- package/dist/useLazyDisposableState.js +32 -39
- package/dist/useLazyDisposableState.mjs +34 -0
- package/dist/useLazyDisposableState.mjs.map +1 -0
- package/dist/useUpdatableDisposableState.d.mts +43 -0
- package/dist/useUpdatableDisposableState.d.mts.map +1 -0
- package/dist/useUpdatableDisposableState.d.ts +10 -7
- package/dist/useUpdatableDisposableState.d.ts.map +1 -1
- package/dist/useUpdatableDisposableState.js +73 -89
- package/dist/useUpdatableDisposableState.mjs +74 -0
- package/dist/useUpdatableDisposableState.mjs.map +1 -0
- package/package.json +14 -6
- package/src/CacheItem.test.ts +4 -7
- package/src/CacheItem.ts +16 -11
- package/src/ParentCache.test.ts +5 -5
- package/src/ParentCache.ts +5 -4
- package/src/useCachedResponsivePrecommitValue.test.tsx +15 -14
- package/src/useCachedResponsivePrecommitValue.ts +4 -4
- package/src/useDisposableState.ts +21 -16
- package/src/useHasCommittedRef.ts +1 -1
- package/src/useLazyDisposableState.test.tsx +2 -2
- package/src/useLazyDisposableState.ts +1 -1
- package/src/useUpdatableDisposableState.test.tsx +19 -5
- package/src/useUpdatableDisposableState.ts +1 -1
- package/dist/index.d.ts.map +0 -1
package/src/CacheItem.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ItemCleanupPair } from '@isograph/disposable-types';
|
|
1
|
+
import type { ItemCleanupPair } from '@isograph/disposable-types';
|
|
2
2
|
import {
|
|
3
3
|
afterEach,
|
|
4
4
|
assert,
|
|
@@ -8,11 +8,8 @@ import {
|
|
|
8
8
|
test,
|
|
9
9
|
vi,
|
|
10
10
|
} from 'vitest';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
CacheItemState,
|
|
14
|
-
createTemporarilyRetainedCacheItem,
|
|
15
|
-
} from './CacheItem';
|
|
11
|
+
import type { CacheItem, CacheItemState } from './CacheItem';
|
|
12
|
+
import { createTemporarilyRetainedCacheItem } from './CacheItem';
|
|
16
13
|
|
|
17
14
|
function getState<T>(cacheItem: CacheItem<T>): CacheItemState<T> {
|
|
18
15
|
return (cacheItem as any).__state as CacheItemState<T>;
|
|
@@ -298,7 +295,7 @@ describe('CacheItem', () => {
|
|
|
298
295
|
assert(state.kind === 'NotInParentCacheAndDisposed');
|
|
299
296
|
|
|
300
297
|
assert(
|
|
301
|
-
cacheItem.permanentRetainIfNotDisposed(disposeTemporaryRetain)
|
|
298
|
+
cacheItem.permanentRetainIfNotDisposed(disposeTemporaryRetain) == null,
|
|
302
299
|
);
|
|
303
300
|
|
|
304
301
|
expect(() => {
|
package/src/CacheItem.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CleanupFn,
|
|
3
3
|
Factory,
|
|
4
4
|
ItemCleanupPair,
|
|
@@ -102,7 +102,7 @@ export class CacheItem<T> {
|
|
|
102
102
|
case 'NotInParentCacheAndNotDisposed': {
|
|
103
103
|
return this.__state.value;
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
case 'NotInParentCacheAndDisposed': {
|
|
106
106
|
throw new Error(
|
|
107
107
|
'Attempted to access disposed value from CacheItem. ' +
|
|
108
108
|
'This indicates a bug in react-disposable-state.',
|
|
@@ -142,7 +142,7 @@ export class CacheItem<T> {
|
|
|
142
142
|
);
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
case 'NotInParentCacheAndDisposed': {
|
|
146
146
|
throw new Error(
|
|
147
147
|
'CacheItem was in a disposed state, but there existed a permanent retain. ' +
|
|
148
148
|
'This indicates a bug in react-disposable-state.',
|
|
@@ -174,7 +174,8 @@ export class CacheItem<T> {
|
|
|
174
174
|
);
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
177
|
-
|
|
177
|
+
case 'InParentCacheAndNotDisposed':
|
|
178
|
+
case 'NotInParentCacheAndDisposed': {
|
|
178
179
|
throw new Error(
|
|
179
180
|
'CacheItem was in an unexpected state. ' +
|
|
180
181
|
'This indicates a bug in react-disposable-state.',
|
|
@@ -184,7 +185,7 @@ export class CacheItem<T> {
|
|
|
184
185
|
},
|
|
185
186
|
];
|
|
186
187
|
}
|
|
187
|
-
|
|
188
|
+
case 'NotInParentCacheAndDisposed': {
|
|
188
189
|
// The CacheItem is disposed, so disposeOfTemporaryRetain is a no-op
|
|
189
190
|
return null;
|
|
190
191
|
}
|
|
@@ -215,7 +216,8 @@ export class CacheItem<T> {
|
|
|
215
216
|
clearTimeout(timeoutId);
|
|
216
217
|
return;
|
|
217
218
|
}
|
|
218
|
-
|
|
219
|
+
case 'NotInParentCacheAndDisposed':
|
|
220
|
+
case 'NotInParentCacheAndNotDisposed': {
|
|
219
221
|
throw new Error(
|
|
220
222
|
'A temporary retain was cleared, for which the CacheItem is in an invalid state. ' +
|
|
221
223
|
'This indicates a bug in react-disposable-state.',
|
|
@@ -233,7 +235,8 @@ export class CacheItem<T> {
|
|
|
233
235
|
this.__maybeExitInParentCacheAndNotDisposedState(this.__state);
|
|
234
236
|
return;
|
|
235
237
|
}
|
|
236
|
-
|
|
238
|
+
case 'NotInParentCacheAndDisposed':
|
|
239
|
+
case 'NotInParentCacheAndNotDisposed': {
|
|
237
240
|
throw new Error(
|
|
238
241
|
'A temporary retain was cleared, for which the CacheItem is in an invalid state. ' +
|
|
239
242
|
'This indicates a bug in react-disposable-state.',
|
|
@@ -248,7 +251,8 @@ export class CacheItem<T> {
|
|
|
248
251
|
);
|
|
249
252
|
return clearTemporaryRetainByCallack;
|
|
250
253
|
}
|
|
251
|
-
|
|
254
|
+
case 'NotInParentCacheAndDisposed':
|
|
255
|
+
case 'NotInParentCacheAndNotDisposed': {
|
|
252
256
|
throw new Error(
|
|
253
257
|
'temporaryRetain was called, for which the CacheItem is in an invalid state. ' +
|
|
254
258
|
'This indicates a bug in react-disposable-state.',
|
|
@@ -281,7 +285,7 @@ export class CacheItem<T> {
|
|
|
281
285
|
this.__maybeExitNotInParentCacheAndNotDisposedState(this.__state);
|
|
282
286
|
return;
|
|
283
287
|
}
|
|
284
|
-
|
|
288
|
+
case 'NotInParentCacheAndDisposed': {
|
|
285
289
|
throw new Error(
|
|
286
290
|
'CacheItem was in a disposed state, but there existed a permanent retain. ' +
|
|
287
291
|
'This indicates a bug in react-disposable-state.',
|
|
@@ -307,7 +311,8 @@ export class CacheItem<T> {
|
|
|
307
311
|
this.__maybeExitNotInParentCacheAndNotDisposedState(this.__state);
|
|
308
312
|
return;
|
|
309
313
|
}
|
|
310
|
-
|
|
314
|
+
case 'InParentCacheAndNotDisposed':
|
|
315
|
+
case 'NotInParentCacheAndDisposed': {
|
|
311
316
|
throw new Error(
|
|
312
317
|
'CacheItem was in an unexpected state. ' +
|
|
313
318
|
'This indicates a bug in react-disposable-state.',
|
|
@@ -316,7 +321,7 @@ export class CacheItem<T> {
|
|
|
316
321
|
}
|
|
317
322
|
};
|
|
318
323
|
}
|
|
319
|
-
|
|
324
|
+
case 'NotInParentCacheAndDisposed': {
|
|
320
325
|
throw new Error(
|
|
321
326
|
'permanentRetain was called, but the CacheItem is in an invalid state. ' +
|
|
322
327
|
'This indicates a bug in react-disposable-state.',
|
package/src/ParentCache.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ItemCleanupPair } from '@isograph/disposable-types';
|
|
1
|
+
import type { ItemCleanupPair } from '@isograph/disposable-types';
|
|
2
2
|
import { assert, describe, expect, test, vi } from 'vitest';
|
|
3
|
-
import { CacheItem } from './CacheItem';
|
|
3
|
+
import type { CacheItem } from './CacheItem';
|
|
4
4
|
import { ParentCache } from './ParentCache';
|
|
5
5
|
|
|
6
6
|
function getValue<T>(cache: ParentCache<T>): CacheItem<T> | null {
|
|
@@ -26,7 +26,7 @@ describe('ParentCache', () => {
|
|
|
26
26
|
assert(getValue(parentCache) != null, 'Parent cache should not be empty');
|
|
27
27
|
|
|
28
28
|
parentCache.empty();
|
|
29
|
-
assert(getValue(parentCache)
|
|
29
|
+
assert(getValue(parentCache) == null);
|
|
30
30
|
|
|
31
31
|
parentCache.getOrPopulateAndTemporaryRetain();
|
|
32
32
|
expect(factory.mock.calls.length).toBe(2);
|
|
@@ -50,7 +50,7 @@ describe('ParentCache', () => {
|
|
|
50
50
|
parentCache.getOrPopulateAndTemporaryRetain();
|
|
51
51
|
clearTemporaryRetain();
|
|
52
52
|
|
|
53
|
-
assert(getValue(parentCache)
|
|
53
|
+
assert(getValue(parentCache) == null);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test('Clearing one of two temporary retains does not remove the item from the parent cache', () => {
|
|
@@ -69,6 +69,6 @@ describe('ParentCache', () => {
|
|
|
69
69
|
assert(getValue(parentCache) != null);
|
|
70
70
|
|
|
71
71
|
clearTemporaryRetain2();
|
|
72
|
-
assert(getValue(parentCache)
|
|
72
|
+
assert(getValue(parentCache) == null);
|
|
73
73
|
});
|
|
74
74
|
});
|
package/src/ParentCache.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CleanupFn,
|
|
3
3
|
Factory,
|
|
4
4
|
ItemCleanupPair,
|
|
5
5
|
} from '@isograph/disposable-types';
|
|
6
|
-
import { CacheItem
|
|
6
|
+
import type { CacheItem } from './CacheItem';
|
|
7
|
+
import { createTemporarilyRetainedCacheItem } from './CacheItem';
|
|
7
8
|
|
|
8
9
|
// TODO convert cache impl to a getter and setter and free functions
|
|
9
10
|
// TODO accept options that get passed to CacheItem
|
|
@@ -51,7 +52,7 @@ export class ParentCache<T> {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
getOrPopulateAndTemporaryRetain(): [CacheItem<T>, T, CleanupFn] {
|
|
54
|
-
return this.__cacheItem
|
|
55
|
+
return this.__cacheItem == null
|
|
55
56
|
? this.__populateAndTemporaryRetain()
|
|
56
57
|
: temporaryRetain(this.__cacheItem);
|
|
57
58
|
}
|
|
@@ -93,7 +94,7 @@ export class ParentCache<T> {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
isEmpty(): boolean {
|
|
96
|
-
return this.__cacheItem
|
|
97
|
+
return this.__cacheItem == null;
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ItemCleanupPair } from '@isograph/disposable-types';
|
|
2
|
-
import React from 'react';
|
|
1
|
+
import type { ItemCleanupPair } from '@isograph/disposable-types';
|
|
2
|
+
import React, { type MutableRefObject } from 'react';
|
|
3
3
|
import { create } from 'react-test-renderer';
|
|
4
4
|
import { assert, describe, expect, test, vi } from 'vitest';
|
|
5
|
-
import { CacheItem, CacheItemState } from './CacheItem';
|
|
5
|
+
import type { CacheItem, CacheItemState } from './CacheItem';
|
|
6
6
|
import { ParentCache } from './ParentCache';
|
|
7
7
|
import { useCachedResponsivePrecommitValue } from './useCachedResponsivePrecommitValue';
|
|
8
8
|
|
|
@@ -14,7 +14,13 @@ function getState<T>(cacheItem: CacheItem<T>): CacheItemState<T> {
|
|
|
14
14
|
return (cacheItem as any).__state;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function Suspender({
|
|
17
|
+
function Suspender({
|
|
18
|
+
promise,
|
|
19
|
+
isResolvedRef,
|
|
20
|
+
}: {
|
|
21
|
+
promise: Promise<unknown>;
|
|
22
|
+
isResolvedRef: MutableRefObject<boolean>;
|
|
23
|
+
}) {
|
|
18
24
|
if (!isResolvedRef.current) {
|
|
19
25
|
throw promise;
|
|
20
26
|
}
|
|
@@ -22,23 +28,18 @@ function Suspender({ promise, isResolvedRef }) {
|
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
function shortPromise() {
|
|
25
|
-
|
|
26
|
-
const promise = new Promise((_resolve) => {
|
|
27
|
-
resolve = _resolve;
|
|
28
|
-
});
|
|
31
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
29
32
|
|
|
30
33
|
setTimeout(resolve, 1);
|
|
31
34
|
return promise;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
function promiseAndResolver() {
|
|
35
|
-
let resolve;
|
|
36
38
|
const isResolvedRef = {
|
|
37
39
|
current: false,
|
|
38
40
|
};
|
|
39
|
-
const promise =
|
|
40
|
-
|
|
41
|
-
});
|
|
41
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
42
|
+
|
|
42
43
|
return {
|
|
43
44
|
promise,
|
|
44
45
|
resolve: () => {
|
|
@@ -51,7 +52,7 @@ function promiseAndResolver() {
|
|
|
51
52
|
|
|
52
53
|
// The fact that sometimes we need to render in concurrent mode and sometimes
|
|
53
54
|
// not is a bit worrisome.
|
|
54
|
-
async function awaitableCreate(Component, isConcurrent) {
|
|
55
|
+
async function awaitableCreate(Component, isConcurrent: boolean) {
|
|
55
56
|
const element = create(
|
|
56
57
|
Component,
|
|
57
58
|
isConcurrent ? { unstable_isConcurrent: true } : undefined,
|
|
@@ -157,7 +158,7 @@ describe('useCachedResponsivePrecommitValue', () => {
|
|
|
157
158
|
setState = _setState;
|
|
158
159
|
const value = useCachedResponsivePrecommitValue(cache, hookOnCommit);
|
|
159
160
|
|
|
160
|
-
if (initialRender && value
|
|
161
|
+
if (initialRender && value != null) {
|
|
161
162
|
initialRender = false;
|
|
162
163
|
expect(value).toEqual({ state: 1 });
|
|
163
164
|
} else {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import { ItemCleanupPair } from '@isograph/disposable-types';
|
|
3
|
+
import type { ItemCleanupPair } from '@isograph/disposable-types';
|
|
4
4
|
import { useEffect, useRef, useState } from 'react';
|
|
5
|
-
import { ParentCache } from './ParentCache';
|
|
5
|
+
import type { ParentCache } from './ParentCache';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* useCachedResponsivePrecommitValue<T>
|
|
@@ -70,14 +70,14 @@ export function useCachedResponsivePrecommitValue<T>(
|
|
|
70
70
|
const undisposedPair = cacheItem.permanentRetainIfNotDisposed(
|
|
71
71
|
disposeOfTemporaryRetain,
|
|
72
72
|
);
|
|
73
|
-
if (undisposedPair
|
|
73
|
+
if (undisposedPair != null) {
|
|
74
74
|
onCommit(undisposedPair);
|
|
75
75
|
} else {
|
|
76
76
|
// The cache item we created during render has been disposed. Check if the parent
|
|
77
77
|
// cache is populated.
|
|
78
78
|
const existingCacheItemCleanupPair =
|
|
79
79
|
parentCache.getAndPermanentRetainIfPresent();
|
|
80
|
-
if (existingCacheItemCleanupPair
|
|
80
|
+
if (existingCacheItemCleanupPair != null) {
|
|
81
81
|
onCommit(existingCacheItemCleanupPair);
|
|
82
82
|
} else {
|
|
83
83
|
// We did not find an item in the parent cache, create a new one.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ItemCleanupPair } from '@isograph/disposable-types';
|
|
1
|
+
import type { ItemCleanupPair } from '@isograph/disposable-types';
|
|
2
2
|
import { useEffect, useRef } from 'react';
|
|
3
|
-
import { ParentCache } from './ParentCache';
|
|
3
|
+
import type { ParentCache } from './ParentCache';
|
|
4
4
|
import { useCachedResponsivePrecommitValue } from './useCachedResponsivePrecommitValue';
|
|
5
5
|
import {
|
|
6
6
|
UNASSIGNED_STATE,
|
|
7
|
-
UnassignedState,
|
|
7
|
+
type UnassignedState,
|
|
8
8
|
useUpdatableDisposableState,
|
|
9
9
|
} from './useUpdatableDisposableState';
|
|
10
10
|
|
|
@@ -32,7 +32,7 @@ export function useDisposableState<T = never>(
|
|
|
32
32
|
useEffect(
|
|
33
33
|
function cleanupItemCleanupPairRefAfterSetState() {
|
|
34
34
|
if (stateFromDisposableStateHook !== UNASSIGNED_STATE) {
|
|
35
|
-
if (itemCleanupPairRef.current
|
|
35
|
+
if (itemCleanupPairRef.current != null) {
|
|
36
36
|
itemCleanupPairRef.current[1]();
|
|
37
37
|
itemCleanupPairRef.current = null;
|
|
38
38
|
} else {
|
|
@@ -48,12 +48,25 @@ export function useDisposableState<T = never>(
|
|
|
48
48
|
|
|
49
49
|
useEffect(function cleanupItemCleanupPairRefIfSetStateNotCalled() {
|
|
50
50
|
return () => {
|
|
51
|
-
if (itemCleanupPairRef.current
|
|
51
|
+
if (itemCleanupPairRef.current != null) {
|
|
52
52
|
itemCleanupPairRef.current[1]();
|
|
53
53
|
itemCleanupPairRef.current = null;
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
}, []);
|
|
57
|
+
const state: T | undefined =
|
|
58
|
+
(stateFromDisposableStateHook !== UNASSIGNED_STATE
|
|
59
|
+
? stateFromDisposableStateHook
|
|
60
|
+
: null) ??
|
|
61
|
+
preCommitItem?.state ??
|
|
62
|
+
itemCleanupPairRef.current?.[0];
|
|
63
|
+
|
|
64
|
+
if (state != null) {
|
|
65
|
+
return {
|
|
66
|
+
state: state,
|
|
67
|
+
setState,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
57
70
|
|
|
58
71
|
// Safety: we can be in one of three states. Pre-commit, in which case
|
|
59
72
|
// preCommitItem is assigned, post-commit but before setState has been
|
|
@@ -68,17 +81,9 @@ export function useDisposableState<T = never>(
|
|
|
68
81
|
// Note that in the post-commit post-setState state, itemCleanupPairRef
|
|
69
82
|
// can still be assigned, during the render before the
|
|
70
83
|
// cleanupItemCleanupPairRefAfterSetState effect is called.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
: null) ??
|
|
75
|
-
preCommitItem?.state ??
|
|
76
|
-
itemCleanupPairRef.current?.[0];
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
state: state!,
|
|
80
|
-
setState,
|
|
81
|
-
};
|
|
84
|
+
throw new Error(
|
|
85
|
+
'state was unexpectedly null. This indicates a bug in react-disposable-state.',
|
|
86
|
+
);
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
// @ts-ignore
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ItemCleanupPair } from '@isograph/disposable-types';
|
|
1
|
+
import type { ItemCleanupPair } from '@isograph/disposable-types';
|
|
2
2
|
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import { create } from 'react-test-renderer';
|
|
4
4
|
import { describe, expect, test, vi } from 'vitest';
|
|
@@ -47,7 +47,7 @@ describe('useLazyDisposableState', async () => {
|
|
|
47
47
|
}, []);
|
|
48
48
|
|
|
49
49
|
useEffect(() => {
|
|
50
|
-
if (state
|
|
50
|
+
if (state === 1) return;
|
|
51
51
|
committed.resolve();
|
|
52
52
|
}, [state]);
|
|
53
53
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { ItemCleanupPair } from '@isograph/isograph-disposable-types';
|
|
4
4
|
import { useEffect, useRef } from 'react';
|
|
5
|
-
import { ParentCache } from './ParentCache';
|
|
5
|
+
import type { ParentCache } from './ParentCache';
|
|
6
6
|
import { useCachedResponsivePrecommitValue } from './useCachedResponsivePrecommitValue';
|
|
7
7
|
import { type UnassignedState } from './useUpdatableDisposableState';
|
|
8
8
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { type MutableRefObject } from 'react';
|
|
2
2
|
import { create } from 'react-test-renderer';
|
|
3
3
|
import { describe, expect, test, vi } from 'vitest';
|
|
4
4
|
import {
|
|
@@ -6,7 +6,13 @@ import {
|
|
|
6
6
|
useUpdatableDisposableState,
|
|
7
7
|
} from './useUpdatableDisposableState';
|
|
8
8
|
|
|
9
|
-
function Suspender({
|
|
9
|
+
function Suspender({
|
|
10
|
+
promise,
|
|
11
|
+
isResolvedRef,
|
|
12
|
+
}: {
|
|
13
|
+
isResolvedRef: MutableRefObject<boolean>;
|
|
14
|
+
promise: Promise<unknown>;
|
|
15
|
+
}) {
|
|
10
16
|
if (!isResolvedRef.current) {
|
|
11
17
|
throw promise;
|
|
12
18
|
}
|
|
@@ -43,7 +49,7 @@ function promiseAndResolver() {
|
|
|
43
49
|
|
|
44
50
|
// The fact that sometimes we need to render in concurrent mode and sometimes
|
|
45
51
|
// not is a bit worrisome.
|
|
46
|
-
async function awaitableCreate(Component, isConcurrent) {
|
|
52
|
+
async function awaitableCreate(Component, isConcurrent: boolean) {
|
|
47
53
|
const element = create(
|
|
48
54
|
Component,
|
|
49
55
|
isConcurrent ? { unstable_isConcurrent: true } : undefined,
|
|
@@ -377,7 +383,11 @@ if (false) {
|
|
|
377
383
|
}
|
|
378
384
|
|
|
379
385
|
let setState;
|
|
380
|
-
function ParentComponent({
|
|
386
|
+
function ParentComponent({
|
|
387
|
+
shouldMountRef,
|
|
388
|
+
}: {
|
|
389
|
+
shouldMountRef: MutableRefObject<boolean>;
|
|
390
|
+
}) {
|
|
381
391
|
const [, _setState] = React.useState();
|
|
382
392
|
setState = _setState;
|
|
383
393
|
return shouldMountRef.current ? (
|
|
@@ -450,7 +460,11 @@ if (false) {
|
|
|
450
460
|
}
|
|
451
461
|
|
|
452
462
|
let setState;
|
|
453
|
-
function ParentComponent({
|
|
463
|
+
function ParentComponent({
|
|
464
|
+
shouldMountRef,
|
|
465
|
+
}: {
|
|
466
|
+
shouldMountRef: MutableRefObject<boolean>;
|
|
467
|
+
}) {
|
|
454
468
|
const [, _setState] = React.useState();
|
|
455
469
|
setState = _setState;
|
|
456
470
|
return shouldMountRef.current ? <TestComponent /> : null;
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAE3C,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,qCAAqC,CAAC;AACpD,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC"}
|