small-state-react 0.2.0 → 0.2.2

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/dist/index.cjs CHANGED
@@ -10,8 +10,12 @@ function useRuntimeHandle(machine, options) {
10
10
  if (!(0, small_state.isMachine)(machine)) throw new Error(`useRuntimeHandle() expects Machine object.`);
11
11
  const rtRef = (0, react.useRef)(null);
12
12
  if (!rtRef.current) rtRef.current = (0, small_state.makeRuntime)(machine, options);
13
+ const retRef = (0, react.useRef)({});
13
14
  (0, react.useEffect)(() => {
14
- if (rtRef.current.runtimeStatus === "stopped") rtRef.current = (0, small_state.makeRuntime)(machine, options);
15
+ if (rtRef.current.runtimeStatus === "stopped") {
16
+ rtRef.current = (0, small_state.makeRuntime)(machine, options);
17
+ retRef.current = {};
18
+ }
15
19
  const crrRt = rtRef.current;
16
20
  options?.onPreStart?.(crrRt);
17
21
  crrRt.start();
@@ -28,12 +32,12 @@ function useRuntimeHandle(machine, options) {
28
32
  const getSnapshot = (0, react.useCallback)(() => runtime.getSnapshot(), [runtime]);
29
33
  snapshot = (0, react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
30
34
  }
31
- return {
32
- snapshot,
33
- send: (event) => void runtime.send.apply(runtime, [event]),
34
- runtime,
35
- useBoundSend: readyToUseBoundSend(rtRef)
36
- };
35
+ const ret = retRef.current;
36
+ ret.snapshot = snapshot;
37
+ ret.send = (event) => void runtime.send.apply(runtime, [event]);
38
+ ret.runtime = runtime;
39
+ ret.useBoundSend = readyToUseBoundSend(rtRef);
40
+ return ret;
37
41
  }
38
42
  // src/react/useSelectedSnapshot.ts
39
43
  const DEFAULT_COMPARE = (a, b) => a === b;
package/dist/index.mjs CHANGED
@@ -9,8 +9,12 @@ function useRuntimeHandle(machine, options) {
9
9
  if (!isMachine(machine)) throw new Error(`useRuntimeHandle() expects Machine object.`);
10
10
  const rtRef = useRef(null);
11
11
  if (!rtRef.current) rtRef.current = makeRuntime(machine, options);
12
+ const retRef = useRef({});
12
13
  useEffect(() => {
13
- if (rtRef.current.runtimeStatus === "stopped") rtRef.current = makeRuntime(machine, options);
14
+ if (rtRef.current.runtimeStatus === "stopped") {
15
+ rtRef.current = makeRuntime(machine, options);
16
+ retRef.current = {};
17
+ }
14
18
  const crrRt = rtRef.current;
15
19
  options?.onPreStart?.(crrRt);
16
20
  crrRt.start();
@@ -27,12 +31,12 @@ function useRuntimeHandle(machine, options) {
27
31
  const getSnapshot = useCallback(() => runtime.getSnapshot(), [runtime]);
28
32
  snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
29
33
  }
30
- return {
31
- snapshot,
32
- send: (event) => void runtime.send.apply(runtime, [event]),
33
- runtime,
34
- useBoundSend: readyToUseBoundSend(rtRef)
35
- };
34
+ const ret = retRef.current;
35
+ ret.snapshot = snapshot;
36
+ ret.send = (event) => void runtime.send.apply(runtime, [event]);
37
+ ret.runtime = runtime;
38
+ ret.useBoundSend = readyToUseBoundSend(rtRef);
39
+ return ret;
36
40
  }
37
41
  // src/react/useSelectedSnapshot.ts
38
42
  const DEFAULT_COMPARE = (a, b) => a === b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "small-state-react",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "React and Jotai bindings for small-state, a lightweight state machine library.",
5
5
  "author": "qyvvy",
6
6
  "license": "MIT",