@isograph/react-disposable-state 0.0.4 → 0.1.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.
@@ -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,7 +59,7 @@ 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
 
@@ -67,14 +67,14 @@ export function useUpdatableDisposableState<
67
67
  const setStateCountRef = useRef(0);
68
68
 
69
69
  const [stateICI, setStateICI] = useState<ICI<T> | UnassignedState>(
70
- UNASSIGNED_STATE
70
+ UNASSIGNED_STATE,
71
71
  );
72
72
 
73
73
  const setStateAfterCommit = useCallback(
74
74
  (itemCleanupPair: ItemCleanupPair<T>) => {
75
75
  if (!hasCommittedRef.current) {
76
76
  throw new Error(
77
- "Calling setState before the component has committed is unsafe and disallowed."
77
+ 'Calling setState before the component has committed is unsafe and disallowed.',
78
78
  );
79
79
  }
80
80
 
@@ -87,7 +87,7 @@ export function useUpdatableDisposableState<
87
87
  undisposedICIs.current.add(ici);
88
88
  setStateICI(ici);
89
89
  },
90
- [setStateICI]
90
+ [setStateICI],
91
91
  );
92
92
 
93
93
  useEffect(function cleanupUnreachableItems() {
@@ -126,9 +126,9 @@ function tsTests() {
126
126
  // @ts-expect-error
127
127
  a.setState([UNASSIGNED_STATE, () => {}]);
128
128
  // @ts-expect-error
129
- a.setState(["asdf", () => {}]);
129
+ a.setState(['asdf', () => {}]);
130
130
  const b = useUpdatableDisposableState<string | UnassignedState>();
131
131
  // @ts-expect-error
132
132
  b.setState([UNASSIGNED_STATE, () => {}]);
133
- b.setState(["asdf", () => {}]);
133
+ b.setState(['asdf', () => {}]);
134
134
  }