@xstate/react 4.0.0-beta.11 → 4.0.0-beta.12

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
1
  import * as React from 'react';
2
2
  import { ActorRefFrom, AnyStateMachine, SnapshotFrom, ActorOptions, AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, StateMachine, AnyActorLogic } from 'xstate';
3
- type ToMachinesWithProvidedImplementations<TMachine extends AnyStateMachine> = TMachine extends StateMachine<infer TContext, infer TEvent, infer TActor, infer TAction, infer TGuard, infer TDelay, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? StateMachine<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : never;
3
+ type ToMachinesWithProvidedImplementations<TMachine extends AnyStateMachine> = TMachine extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer TActor, infer TAction, infer TGuard, infer TDelay, infer TStateValue, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : never;
4
4
  export declare function createActorContext<TLogic extends AnyActorLogic>(actorLogic: TLogic, interpreterOptions?: ActorOptions<TLogic>): {
5
5
  useSelector: <T>(selector: (snapshot: SnapshotFrom<TLogic>) => T, compare?: (a: T, b: T) => boolean) => T;
6
6
  useActorRef: () => ActorRefFrom<TLogic>;
@@ -1,3 +1,3 @@
1
1
  import { AnyActorLogic, AnyActor, ActorRefFrom, ActorOptions, Observer, SnapshotFrom } from 'xstate';
2
- export declare function useIdleActor(logic: AnyActorLogic, options: Partial<ActorOptions<AnyActorLogic>>): AnyActor;
2
+ export declare function useIdleActorRef(logic: AnyActorLogic, options: Partial<ActorOptions<AnyActorLogic>>): AnyActor;
3
3
  export declare function useActorRef<TLogic extends AnyActorLogic>(machine: TLogic, options?: ActorOptions<TLogic>, observerOrListener?: Observer<SnapshotFrom<TLogic>> | ((value: SnapshotFrom<TLogic>) => void)): ActorRefFrom<TLogic>;
@@ -41,14 +41,14 @@ const forEachActor = (actorRef, callback) => {
41
41
  }
42
42
  };
43
43
  function stopRootWithRehydration(actorRef) {
44
- // persist state here in a custom way allows us to persist inline actors and to preserve actor references
44
+ // persist snapshot here in a custom way allows us to persist inline actors and to preserve actor references
45
45
  // we do it to avoid setState in useEffect when the effect gets "reconnected"
46
46
  // this currently only happens in Strict Effects but it simulates the Offscreen aka Activity API
47
47
  // it also just allows us to end up with a somewhat more predictable behavior for the users
48
48
  const persistedSnapshots = [];
49
49
  forEachActor(actorRef, ref => {
50
50
  persistedSnapshots.push([ref, ref.getSnapshot()]);
51
- // muting observers allow us to avoid `useSelector` from being notified about the stopped state
51
+ // muting observers allow us to avoid `useSelector` from being notified about the stopped snapshot
52
52
  // React reconnects its subscribers (from the useSyncExternalStore) on its own
53
53
  // and userland subscibers should basically always do the same anyway
54
54
  // as each subscription should have its own cleanup logic and that should be called each such reconnect
@@ -57,11 +57,11 @@ function stopRootWithRehydration(actorRef) {
57
57
  actorRef.stop();
58
58
  persistedSnapshots.forEach(([ref, snapshot]) => {
59
59
  ref._processingStatus = 0;
60
- ref._state = snapshot;
60
+ ref._snapshot = snapshot;
61
61
  });
62
62
  }
63
63
 
64
- function useIdleActor(logic, options) {
64
+ function useIdleActorRef(logic, options) {
65
65
  let [[currentConfig, actorRef], setCurrent] = React.useState(() => {
66
66
  const actorRef = xstate.createActor(logic, options);
67
67
  return [logic.config, actorRef];
@@ -69,7 +69,7 @@ function useIdleActor(logic, options) {
69
69
  if (logic.config !== currentConfig) {
70
70
  const newActorRef = xstate.createActor(logic, {
71
71
  ...options,
72
- state: actorRef.getPersistedState({
72
+ snapshot: actorRef.getPersistedSnapshot({
73
73
  __unsafeAllowInlineActors: true
74
74
  })
75
75
  });
@@ -84,7 +84,7 @@ function useIdleActor(logic, options) {
84
84
  return actorRef;
85
85
  }
86
86
  function useActorRef(machine, options = {}, observerOrListener) {
87
- const actorRef = useIdleActor(machine, options);
87
+ const actorRef = useIdleActorRef(machine, options);
88
88
  React.useEffect(() => {
89
89
  if (!observerOrListener) {
90
90
  return;
@@ -104,7 +104,7 @@ function useActorRef(machine, options = {}, observerOrListener) {
104
104
  }
105
105
 
106
106
  function useActor(logic, options = {}) {
107
- const actorRef = useIdleActor(logic, options);
107
+ const actorRef = useIdleActorRef(logic, options);
108
108
  const getSnapshot = React.useCallback(() => {
109
109
  return actorRef.getSnapshot();
110
110
  }, [actorRef]);
@@ -41,14 +41,14 @@ const forEachActor = (actorRef, callback) => {
41
41
  }
42
42
  };
43
43
  function stopRootWithRehydration(actorRef) {
44
- // persist state here in a custom way allows us to persist inline actors and to preserve actor references
44
+ // persist snapshot here in a custom way allows us to persist inline actors and to preserve actor references
45
45
  // we do it to avoid setState in useEffect when the effect gets "reconnected"
46
46
  // this currently only happens in Strict Effects but it simulates the Offscreen aka Activity API
47
47
  // it also just allows us to end up with a somewhat more predictable behavior for the users
48
48
  const persistedSnapshots = [];
49
49
  forEachActor(actorRef, ref => {
50
50
  persistedSnapshots.push([ref, ref.getSnapshot()]);
51
- // muting observers allow us to avoid `useSelector` from being notified about the stopped state
51
+ // muting observers allow us to avoid `useSelector` from being notified about the stopped snapshot
52
52
  // React reconnects its subscribers (from the useSyncExternalStore) on its own
53
53
  // and userland subscibers should basically always do the same anyway
54
54
  // as each subscription should have its own cleanup logic and that should be called each such reconnect
@@ -57,11 +57,11 @@ function stopRootWithRehydration(actorRef) {
57
57
  actorRef.stop();
58
58
  persistedSnapshots.forEach(([ref, snapshot]) => {
59
59
  ref._processingStatus = 0;
60
- ref._state = snapshot;
60
+ ref._snapshot = snapshot;
61
61
  });
62
62
  }
63
63
 
64
- function useIdleActor(logic, options) {
64
+ function useIdleActorRef(logic, options) {
65
65
  let [[currentConfig, actorRef], setCurrent] = React.useState(() => {
66
66
  const actorRef = xstate.createActor(logic, options);
67
67
  return [logic.config, actorRef];
@@ -69,7 +69,7 @@ function useIdleActor(logic, options) {
69
69
  if (logic.config !== currentConfig) {
70
70
  const newActorRef = xstate.createActor(logic, {
71
71
  ...options,
72
- state: actorRef.getPersistedState({
72
+ snapshot: actorRef.getPersistedSnapshot({
73
73
  __unsafeAllowInlineActors: true
74
74
  })
75
75
  });
@@ -84,7 +84,7 @@ function useIdleActor(logic, options) {
84
84
  return actorRef;
85
85
  }
86
86
  function useActorRef(machine, options = {}, observerOrListener) {
87
- const actorRef = useIdleActor(machine, options);
87
+ const actorRef = useIdleActorRef(machine, options);
88
88
  React.useEffect(() => {
89
89
  if (!observerOrListener) {
90
90
  return;
@@ -107,7 +107,7 @@ function useActor(logic, options = {}) {
107
107
  if (!!logic && 'send' in logic && typeof logic.send === 'function') {
108
108
  throw new Error(`useActor() expects actor logic (e.g. a machine), but received an ActorRef. Use the useSelector(actorRef, ...) hook instead to read the ActorRef's snapshot.`);
109
109
  }
110
- const actorRef = useIdleActor(logic, options);
110
+ const actorRef = useIdleActorRef(logic, options);
111
111
  const getSnapshot = React.useCallback(() => {
112
112
  return actorRef.getSnapshot();
113
113
  }, [actorRef]);
@@ -15,14 +15,14 @@ const forEachActor = (actorRef, callback) => {
15
15
  }
16
16
  };
17
17
  function stopRootWithRehydration(actorRef) {
18
- // persist state here in a custom way allows us to persist inline actors and to preserve actor references
18
+ // persist snapshot here in a custom way allows us to persist inline actors and to preserve actor references
19
19
  // we do it to avoid setState in useEffect when the effect gets "reconnected"
20
20
  // this currently only happens in Strict Effects but it simulates the Offscreen aka Activity API
21
21
  // it also just allows us to end up with a somewhat more predictable behavior for the users
22
22
  const persistedSnapshots = [];
23
23
  forEachActor(actorRef, ref => {
24
24
  persistedSnapshots.push([ref, ref.getSnapshot()]);
25
- // muting observers allow us to avoid `useSelector` from being notified about the stopped state
25
+ // muting observers allow us to avoid `useSelector` from being notified about the stopped snapshot
26
26
  // React reconnects its subscribers (from the useSyncExternalStore) on its own
27
27
  // and userland subscibers should basically always do the same anyway
28
28
  // as each subscription should have its own cleanup logic and that should be called each such reconnect
@@ -31,11 +31,11 @@ function stopRootWithRehydration(actorRef) {
31
31
  actorRef.stop();
32
32
  persistedSnapshots.forEach(([ref, snapshot]) => {
33
33
  ref._processingStatus = 0;
34
- ref._state = snapshot;
34
+ ref._snapshot = snapshot;
35
35
  });
36
36
  }
37
37
 
38
- function useIdleActor(logic, options) {
38
+ function useIdleActorRef(logic, options) {
39
39
  let [[currentConfig, actorRef], setCurrent] = useState(() => {
40
40
  const actorRef = createActor(logic, options);
41
41
  return [logic.config, actorRef];
@@ -43,7 +43,7 @@ function useIdleActor(logic, options) {
43
43
  if (logic.config !== currentConfig) {
44
44
  const newActorRef = createActor(logic, {
45
45
  ...options,
46
- state: actorRef.getPersistedState({
46
+ snapshot: actorRef.getPersistedSnapshot({
47
47
  __unsafeAllowInlineActors: true
48
48
  })
49
49
  });
@@ -58,7 +58,7 @@ function useIdleActor(logic, options) {
58
58
  return actorRef;
59
59
  }
60
60
  function useActorRef(machine, options = {}, observerOrListener) {
61
- const actorRef = useIdleActor(machine, options);
61
+ const actorRef = useIdleActorRef(machine, options);
62
62
  useEffect(() => {
63
63
  if (!observerOrListener) {
64
64
  return;
@@ -81,7 +81,7 @@ function useActor(logic, options = {}) {
81
81
  if (!!logic && 'send' in logic && typeof logic.send === 'function') {
82
82
  throw new Error(`useActor() expects actor logic (e.g. a machine), but received an ActorRef. Use the useSelector(actorRef, ...) hook instead to read the ActorRef's snapshot.`);
83
83
  }
84
- const actorRef = useIdleActor(logic, options);
84
+ const actorRef = useIdleActorRef(logic, options);
85
85
  const getSnapshot = useCallback(() => {
86
86
  return actorRef.getSnapshot();
87
87
  }, [actorRef]);
@@ -15,14 +15,14 @@ const forEachActor = (actorRef, callback) => {
15
15
  }
16
16
  };
17
17
  function stopRootWithRehydration(actorRef) {
18
- // persist state here in a custom way allows us to persist inline actors and to preserve actor references
18
+ // persist snapshot here in a custom way allows us to persist inline actors and to preserve actor references
19
19
  // we do it to avoid setState in useEffect when the effect gets "reconnected"
20
20
  // this currently only happens in Strict Effects but it simulates the Offscreen aka Activity API
21
21
  // it also just allows us to end up with a somewhat more predictable behavior for the users
22
22
  const persistedSnapshots = [];
23
23
  forEachActor(actorRef, ref => {
24
24
  persistedSnapshots.push([ref, ref.getSnapshot()]);
25
- // muting observers allow us to avoid `useSelector` from being notified about the stopped state
25
+ // muting observers allow us to avoid `useSelector` from being notified about the stopped snapshot
26
26
  // React reconnects its subscribers (from the useSyncExternalStore) on its own
27
27
  // and userland subscibers should basically always do the same anyway
28
28
  // as each subscription should have its own cleanup logic and that should be called each such reconnect
@@ -31,11 +31,11 @@ function stopRootWithRehydration(actorRef) {
31
31
  actorRef.stop();
32
32
  persistedSnapshots.forEach(([ref, snapshot]) => {
33
33
  ref._processingStatus = 0;
34
- ref._state = snapshot;
34
+ ref._snapshot = snapshot;
35
35
  });
36
36
  }
37
37
 
38
- function useIdleActor(logic, options) {
38
+ function useIdleActorRef(logic, options) {
39
39
  let [[currentConfig, actorRef], setCurrent] = useState(() => {
40
40
  const actorRef = createActor(logic, options);
41
41
  return [logic.config, actorRef];
@@ -43,7 +43,7 @@ function useIdleActor(logic, options) {
43
43
  if (logic.config !== currentConfig) {
44
44
  const newActorRef = createActor(logic, {
45
45
  ...options,
46
- state: actorRef.getPersistedState({
46
+ snapshot: actorRef.getPersistedSnapshot({
47
47
  __unsafeAllowInlineActors: true
48
48
  })
49
49
  });
@@ -58,7 +58,7 @@ function useIdleActor(logic, options) {
58
58
  return actorRef;
59
59
  }
60
60
  function useActorRef(machine, options = {}, observerOrListener) {
61
- const actorRef = useIdleActor(machine, options);
61
+ const actorRef = useIdleActorRef(machine, options);
62
62
  useEffect(() => {
63
63
  if (!observerOrListener) {
64
64
  return;
@@ -78,7 +78,7 @@ function useActorRef(machine, options = {}, observerOrListener) {
78
78
  }
79
79
 
80
80
  function useActor(logic, options = {}) {
81
- const actorRef = useIdleActor(logic, options);
81
+ const actorRef = useIdleActorRef(logic, options);
82
82
  const getSnapshot = useCallback(() => {
83
83
  return actorRef.getSnapshot();
84
84
  }, [actorRef]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xstate/react",
3
- "version": "4.0.0-beta.11",
3
+ "version": "4.0.0-beta.12",
4
4
  "description": "XState tools for React",
5
5
  "keywords": [
6
6
  "state",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "peerDependencies": {
57
57
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
58
- "xstate": "^5.0.0-beta.41"
58
+ "xstate": "^5.0.0-beta.54"
59
59
  },
60
60
  "peerDependenciesMeta": {
61
61
  "xstate": {
@@ -76,6 +76,6 @@
76
76
  "jsdom-global": "^3.0.2",
77
77
  "react": "^18.0.0",
78
78
  "react-dom": "^18.0.0",
79
- "xstate": "5.0.0-beta.41"
79
+ "xstate": "5.0.0-beta.54"
80
80
  }
81
81
  }