@isograph/react-disposable-state 0.1.0 → 0.2.0

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.
@@ -21,6 +21,8 @@ const CacheItem_1 = require("./CacheItem");
21
21
  * be called
22
22
  */
23
23
  class ParentCache {
24
+ // TODO pass an onEmpty function, which can e.g. remove this ParentCache
25
+ // from some parent object.
24
26
  constructor(factory) {
25
27
  this.__cacheItem = null;
26
28
  this.__factory = factory;
@@ -1,5 +1,5 @@
1
1
  import { ParentCache } from './ParentCache';
2
- import { ItemCleanupPair } from '@isograph/isograph-disposable-types/dist';
2
+ import { ItemCleanupPair } from '@isograph/disposable-types';
3
3
  /**
4
4
  * usePrecommitValue<T>
5
5
  * - Takes a mutable parent cache, a factory function, and an onCommit callback.
@@ -9,7 +9,7 @@ import { ItemCleanupPair } from '@isograph/isograph-disposable-types/dist';
9
9
  * disposed by the time of the commit. If so, this hook checks the parent cache
10
10
  * for another T or creates one, and passes this T to onCommit.
11
11
  * - If the T returned during the last render is not the same as the one that
12
- * is passed to onCommit, during the commit phase, will schedule another render.
12
+ * is passed to onCommit, during the commit phase, it will schedule another render.
13
13
  *
14
14
  * Invariant: the returned T has not been disposed during the tick of the render.
15
15
  * The T passed to the onCommit callback has not been disposed when the onCommit
@@ -12,7 +12,7 @@ const useHasCommittedRef_1 = require("./useHasCommittedRef");
12
12
  * disposed by the time of the commit. If so, this hook checks the parent cache
13
13
  * for another T or creates one, and passes this T to onCommit.
14
14
  * - If the T returned during the last render is not the same as the one that
15
- * is passed to onCommit, during the commit phase, will schedule another render.
15
+ * is passed to onCommit, during the commit phase, it will schedule another render.
16
16
  *
17
17
  * Invariant: the returned T has not been disposed during the tick of the render.
18
18
  * The T passed to the onCommit callback has not been disposed when the onCommit
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@isograph/react-disposable-state",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Primitives for managing disposable state in React",
5
+ "homepage": "https://isograph.dev",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
7
8
  "author": "Isograph Labs",
@@ -13,11 +14,14 @@
13
14
  "test-watch": "vitest watch",
14
15
  "coverage": "vitest run --coverage",
15
16
  "note": "WE SHOULD ALSO TEST HERE",
16
- "prepack": "yarn run compile"
17
+ "prepack": "yarn run compile",
18
+ "tsc": "tsc"
17
19
  },
18
20
  "dependencies": {
19
- "@isograph/disposable-types": "0.1.0",
20
- "react": "^18.2.0"
21
+ "@isograph/disposable-types": "0.2.0"
22
+ },
23
+ "peerDependencies": {
24
+ "react": "18.2.0"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@types/react": "^18.0.31",
@@ -29,5 +33,6 @@
29
33
  "type": "git",
30
34
  "url": "git+https://github.com/isographlabs/isograph.git",
31
35
  "directory": "libs/isograph-react-disposable-state"
32
- }
36
+ },
37
+ "sideEffects": false
33
38
  }
@@ -28,6 +28,8 @@ export class ParentCache<T> {
28
28
  private __cacheItem: CacheItem<T> | null = null;
29
29
  private readonly __factory: Factory<T>;
30
30
 
31
+ // TODO pass an onEmpty function, which can e.g. remove this ParentCache
32
+ // from some parent object.
31
33
  constructor(factory: Factory<T>) {
32
34
  this.__factory = factory;
33
35
  }
@@ -3,7 +3,7 @@
3
3
  import { useEffect, useState } from 'react';
4
4
  import { ParentCache } from './ParentCache';
5
5
  import { useHasCommittedRef } from './useHasCommittedRef';
6
- import { ItemCleanupPair } from '@isograph/isograph-disposable-types/dist';
6
+ import { ItemCleanupPair } from '@isograph/disposable-types';
7
7
 
8
8
  /**
9
9
  * usePrecommitValue<T>
@@ -14,7 +14,7 @@ import { ItemCleanupPair } from '@isograph/isograph-disposable-types/dist';
14
14
  * disposed by the time of the commit. If so, this hook checks the parent cache
15
15
  * for another T or creates one, and passes this T to onCommit.
16
16
  * - If the T returned during the last render is not the same as the one that
17
- * is passed to onCommit, during the commit phase, will schedule another render.
17
+ * is passed to onCommit, during the commit phase, it will schedule another render.
18
18
  *
19
19
  * Invariant: the returned T has not been disposed during the tick of the render.
20
20
  * The T passed to the onCommit callback has not been disposed when the onCommit
@@ -2,7 +2,7 @@ import { ItemCleanupPair } from '@isograph/disposable-types';
2
2
  import { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import { useHasCommittedRef } from './useHasCommittedRef';
4
4
 
5
- export const UNASSIGNED_STATE = Symbol();
5
+ export const UNASSIGNED_STATE: unique symbol = Symbol();
6
6
  export type UnassignedState = typeof UNASSIGNED_STATE;
7
7
 
8
8
  type UseUpdatableDisposableStateReturnValue<T> = {
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "./tsconfig.pkg.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ },
6
+ }