@isograph/react-disposable-state 0.0.0-main-1cd3db6d → 0.0.0-main-2c275831

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.
@@ -1,6 +1,6 @@
1
- import { ItemCleanupPair } from "@isograph/disposable-types";
2
- import { useCallback, useEffect, useRef, useState } from "react";
3
- import { useHasCommittedRef } from "./useHasCommittedRef";
1
+ import { ItemCleanupPair } from '@isograph/disposable-types';
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { useHasCommittedRef } from './useHasCommittedRef';
4
4
 
5
5
  export const UNASSIGNED_STATE = Symbol();
6
6
  export type UnassignedState = typeof UNASSIGNED_STATE;
@@ -59,22 +59,20 @@ type ICI<T> = { item: T; cleanup: () => void; index: number };
59
59
  * - This may only work in concurrent mode, though.
60
60
  */
61
61
  export function useUpdatableDisposableState<
62
- T = never
62
+ T = never,
63
63
  >(): UseUpdatableDisposableStateReturnValue<T> {
64
64
  const hasCommittedRef = useHasCommittedRef();
65
65
 
66
66
  const undisposedICIs = useRef(new Set<ICI<T>>());
67
67
  const setStateCountRef = useRef(0);
68
68
 
69
- const [stateICI, setStateICI] = useState<ICI<T> | UnassignedState>(
70
- UNASSIGNED_STATE
71
- );
69
+ const [stateICI, setStateICI] = useState<ICI<T> | UnassignedState>(UNASSIGNED_STATE);
72
70
 
73
71
  const setStateAfterCommit = useCallback(
74
72
  (itemCleanupPair: ItemCleanupPair<T>) => {
75
73
  if (!hasCommittedRef.current) {
76
74
  throw new Error(
77
- "Calling setState before the component has committed is unsafe and disallowed."
75
+ 'Calling setState before the component has committed is unsafe and disallowed.',
78
76
  );
79
77
  }
80
78
 
@@ -87,7 +85,7 @@ export function useUpdatableDisposableState<
87
85
  undisposedICIs.current.add(ici);
88
86
  setStateICI(ici);
89
87
  },
90
- [setStateICI]
88
+ [setStateICI],
91
89
  );
92
90
 
93
91
  useEffect(function cleanupUnreachableItems() {
@@ -126,9 +124,9 @@ function tsTests() {
126
124
  // @ts-expect-error
127
125
  a.setState([UNASSIGNED_STATE, () => {}]);
128
126
  // @ts-expect-error
129
- a.setState(["asdf", () => {}]);
127
+ a.setState(['asdf', () => {}]);
130
128
  const b = useUpdatableDisposableState<string | UnassignedState>();
131
129
  // @ts-expect-error
132
130
  b.setState([UNASSIGNED_STATE, () => {}]);
133
- b.setState(["asdf", () => {}]);
131
+ b.setState(['asdf', () => {}]);
134
132
  }