@xstate/react 7.0.0-alpha.4 → 7.0.0-alpha.6
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.
|
@@ -6,8 +6,6 @@ export declare function createActorContext<TLogic extends AnyActorLogic>(actorLo
|
|
|
6
6
|
Provider: (props: {
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
options?: ActorOptions<TLogic>;
|
|
9
|
-
/** @deprecated Use `logic` instead. */
|
|
10
|
-
machine?: never;
|
|
11
9
|
logic?: TLogic;
|
|
12
10
|
}) => React.ReactElement<any, any>;
|
|
13
11
|
};
|
package/dist/xstate-react.cjs.js
CHANGED
|
@@ -31,9 +31,19 @@ function _interopNamespace(e) {
|
|
|
31
31
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
32
|
var useIsomorphicLayoutEffect__default = /*#__PURE__*/_interopDefault(useIsomorphicLayoutEffect);
|
|
33
33
|
|
|
34
|
+
function isStateMachine(logic) {
|
|
35
|
+
return typeof logic.provide === 'function' && !!logic.config && !!logic.sources;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The hook updates the sources of its machine on later renders. A per-hook
|
|
39
|
+
// copy keeps those updates from reaching the caller's machine, which may be
|
|
40
|
+
// shared by other actors.
|
|
41
|
+
function ownLogic(logic) {
|
|
42
|
+
return isStateMachine(logic) ? logic.provide({}) : logic;
|
|
43
|
+
}
|
|
34
44
|
function useIdleActorRef(logic, ...[options]) {
|
|
35
45
|
const [actorRef, setActorRef] = React.useState(() => {
|
|
36
|
-
return xstate.createActor(logic, options);
|
|
46
|
+
return xstate.createActor(ownLogic(logic), options);
|
|
37
47
|
});
|
|
38
48
|
// An object whose identity changes only when React Fast Refresh re-renders
|
|
39
49
|
// this component. Fast Refresh ignores dependency lists while it applies an
|
|
@@ -51,7 +61,9 @@ function useIdleActorRef(logic, ...[options]) {
|
|
|
51
61
|
refreshSignalRef.current !== refreshSignal;
|
|
52
62
|
refreshSignalRef.current = refreshSignal;
|
|
53
63
|
if (logic.config === currentLogic.config) {
|
|
54
|
-
currentLogic
|
|
64
|
+
if (isStateMachine(logic) && isStateMachine(currentLogic)) {
|
|
65
|
+
currentLogic.sources = logic.sources;
|
|
66
|
+
}
|
|
55
67
|
return;
|
|
56
68
|
}
|
|
57
69
|
});
|
|
@@ -97,7 +109,7 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
97
109
|
if (!observerOrListener) {
|
|
98
110
|
return;
|
|
99
111
|
}
|
|
100
|
-
const sub = actorRef.subscribe(xstate.
|
|
112
|
+
const sub = actorRef.subscribe(xstate._toObserver(observerOrListener));
|
|
101
113
|
return () => {
|
|
102
114
|
sub.unsubscribe();
|
|
103
115
|
};
|
|
@@ -139,12 +151,8 @@ function createActorContext(actorLogic, actorOptions) {
|
|
|
139
151
|
function Provider({
|
|
140
152
|
children,
|
|
141
153
|
logic: providedLogic = actorLogic,
|
|
142
|
-
machine,
|
|
143
154
|
options: providedOptions
|
|
144
155
|
}) {
|
|
145
|
-
if (machine) {
|
|
146
|
-
throw new Error(`The "machine" prop has been deprecated. Please use "logic" instead.`);
|
|
147
|
-
}
|
|
148
156
|
const actor = useActorRef(providedLogic, {
|
|
149
157
|
...actorOptions,
|
|
150
158
|
...providedOptions
|
|
@@ -31,9 +31,19 @@ function _interopNamespace(e) {
|
|
|
31
31
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
32
|
var useIsomorphicLayoutEffect__default = /*#__PURE__*/_interopDefault(useIsomorphicLayoutEffect);
|
|
33
33
|
|
|
34
|
+
function isStateMachine(logic) {
|
|
35
|
+
return typeof logic.provide === 'function' && !!logic.config && !!logic.sources;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The hook updates the sources of its machine on later renders. A per-hook
|
|
39
|
+
// copy keeps those updates from reaching the caller's machine, which may be
|
|
40
|
+
// shared by other actors.
|
|
41
|
+
function ownLogic(logic) {
|
|
42
|
+
return isStateMachine(logic) ? logic.provide({}) : logic;
|
|
43
|
+
}
|
|
34
44
|
function useIdleActorRef(logic, ...[options]) {
|
|
35
45
|
const [actorRef, setActorRef] = React.useState(() => {
|
|
36
|
-
return xstate.createActor(logic, options);
|
|
46
|
+
return xstate.createActor(ownLogic(logic), options);
|
|
37
47
|
});
|
|
38
48
|
// An object whose identity changes only when React Fast Refresh re-renders
|
|
39
49
|
// this component. Fast Refresh ignores dependency lists while it applies an
|
|
@@ -51,7 +61,9 @@ function useIdleActorRef(logic, ...[options]) {
|
|
|
51
61
|
const refreshed = refreshSignalRef.current !== refreshSignal;
|
|
52
62
|
refreshSignalRef.current = refreshSignal;
|
|
53
63
|
if (logic.config === currentLogic.config) {
|
|
54
|
-
currentLogic
|
|
64
|
+
if (isStateMachine(logic) && isStateMachine(currentLogic)) {
|
|
65
|
+
currentLogic.sources = logic.sources;
|
|
66
|
+
}
|
|
55
67
|
return;
|
|
56
68
|
}
|
|
57
69
|
|
|
@@ -59,8 +71,9 @@ function useIdleActorRef(logic, ...[options]) {
|
|
|
59
71
|
// defines the machine. Keep the running actor and carry its live snapshot
|
|
60
72
|
// over to the new machine; start a fresh actor if it cannot be carried.
|
|
61
73
|
if (refreshed) {
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
const nextLogic = ownLogic(logic);
|
|
75
|
+
if (!xstate._hotSwapActorLogic(actorRef, nextLogic)) {
|
|
76
|
+
setActorRef(xstate.createActor(nextLogic, options));
|
|
64
77
|
}
|
|
65
78
|
}
|
|
66
79
|
});
|
|
@@ -106,7 +119,7 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
106
119
|
if (!observerOrListener) {
|
|
107
120
|
return;
|
|
108
121
|
}
|
|
109
|
-
const sub = actorRef.subscribe(xstate.
|
|
122
|
+
const sub = actorRef.subscribe(xstate._toObserver(observerOrListener));
|
|
110
123
|
return () => {
|
|
111
124
|
sub.unsubscribe();
|
|
112
125
|
};
|
|
@@ -148,12 +161,8 @@ function createActorContext(actorLogic, actorOptions) {
|
|
|
148
161
|
function Provider({
|
|
149
162
|
children,
|
|
150
163
|
logic: providedLogic = actorLogic,
|
|
151
|
-
machine,
|
|
152
164
|
options: providedOptions
|
|
153
165
|
}) {
|
|
154
|
-
if (machine) {
|
|
155
|
-
throw new Error(`The "machine" prop has been deprecated. Please use "logic" instead.`);
|
|
156
|
-
}
|
|
157
166
|
const actor = useActorRef(providedLogic, {
|
|
158
167
|
...actorOptions,
|
|
159
168
|
...providedOptions
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useEffect, useState, useMemo, useRef, useCallback } from 'react';
|
|
3
3
|
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
|
|
4
|
-
import {
|
|
4
|
+
import { _toObserver, createActor, _hotSwapActorLogic } from 'xstate';
|
|
5
5
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
6
6
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
7
7
|
|
|
8
|
+
function isStateMachine(logic) {
|
|
9
|
+
return typeof logic.provide === 'function' && !!logic.config && !!logic.sources;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// The hook updates the sources of its machine on later renders. A per-hook
|
|
13
|
+
// copy keeps those updates from reaching the caller's machine, which may be
|
|
14
|
+
// shared by other actors.
|
|
15
|
+
function ownLogic(logic) {
|
|
16
|
+
return isStateMachine(logic) ? logic.provide({}) : logic;
|
|
17
|
+
}
|
|
8
18
|
function useIdleActorRef(logic, ...[options]) {
|
|
9
19
|
const [actorRef, setActorRef] = useState(() => {
|
|
10
|
-
return createActor(logic, options);
|
|
20
|
+
return createActor(ownLogic(logic), options);
|
|
11
21
|
});
|
|
12
22
|
// An object whose identity changes only when React Fast Refresh re-renders
|
|
13
23
|
// this component. Fast Refresh ignores dependency lists while it applies an
|
|
@@ -25,7 +35,9 @@ function useIdleActorRef(logic, ...[options]) {
|
|
|
25
35
|
const refreshed = refreshSignalRef.current !== refreshSignal;
|
|
26
36
|
refreshSignalRef.current = refreshSignal;
|
|
27
37
|
if (logic.config === currentLogic.config) {
|
|
28
|
-
currentLogic
|
|
38
|
+
if (isStateMachine(logic) && isStateMachine(currentLogic)) {
|
|
39
|
+
currentLogic.sources = logic.sources;
|
|
40
|
+
}
|
|
29
41
|
return;
|
|
30
42
|
}
|
|
31
43
|
|
|
@@ -33,8 +45,9 @@ function useIdleActorRef(logic, ...[options]) {
|
|
|
33
45
|
// defines the machine. Keep the running actor and carry its live snapshot
|
|
34
46
|
// over to the new machine; start a fresh actor if it cannot be carried.
|
|
35
47
|
if (refreshed) {
|
|
36
|
-
|
|
37
|
-
|
|
48
|
+
const nextLogic = ownLogic(logic);
|
|
49
|
+
if (!_hotSwapActorLogic(actorRef, nextLogic)) {
|
|
50
|
+
setActorRef(createActor(nextLogic, options));
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
53
|
});
|
|
@@ -80,7 +93,7 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
80
93
|
if (!observerOrListener) {
|
|
81
94
|
return;
|
|
82
95
|
}
|
|
83
|
-
const sub = actorRef.subscribe(
|
|
96
|
+
const sub = actorRef.subscribe(_toObserver(observerOrListener));
|
|
84
97
|
return () => {
|
|
85
98
|
sub.unsubscribe();
|
|
86
99
|
};
|
|
@@ -122,12 +135,8 @@ function createActorContext(actorLogic, actorOptions) {
|
|
|
122
135
|
function Provider({
|
|
123
136
|
children,
|
|
124
137
|
logic: providedLogic = actorLogic,
|
|
125
|
-
machine,
|
|
126
138
|
options: providedOptions
|
|
127
139
|
}) {
|
|
128
|
-
if (machine) {
|
|
129
|
-
throw new Error(`The "machine" prop has been deprecated. Please use "logic" instead.`);
|
|
130
|
-
}
|
|
131
140
|
const actor = useActorRef(providedLogic, {
|
|
132
141
|
...actorOptions,
|
|
133
142
|
...providedOptions
|
package/dist/xstate-react.esm.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useEffect, useState, useMemo, useRef, useCallback } from 'react';
|
|
3
3
|
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
|
|
4
|
-
import {
|
|
4
|
+
import { _toObserver, createActor } from 'xstate';
|
|
5
5
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
6
6
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
7
7
|
|
|
8
|
+
function isStateMachine(logic) {
|
|
9
|
+
return typeof logic.provide === 'function' && !!logic.config && !!logic.sources;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// The hook updates the sources of its machine on later renders. A per-hook
|
|
13
|
+
// copy keeps those updates from reaching the caller's machine, which may be
|
|
14
|
+
// shared by other actors.
|
|
15
|
+
function ownLogic(logic) {
|
|
16
|
+
return isStateMachine(logic) ? logic.provide({}) : logic;
|
|
17
|
+
}
|
|
8
18
|
function useIdleActorRef(logic, ...[options]) {
|
|
9
19
|
const [actorRef, setActorRef] = useState(() => {
|
|
10
|
-
return createActor(logic, options);
|
|
20
|
+
return createActor(ownLogic(logic), options);
|
|
11
21
|
});
|
|
12
22
|
// An object whose identity changes only when React Fast Refresh re-renders
|
|
13
23
|
// this component. Fast Refresh ignores dependency lists while it applies an
|
|
@@ -25,7 +35,9 @@ function useIdleActorRef(logic, ...[options]) {
|
|
|
25
35
|
refreshSignalRef.current !== refreshSignal;
|
|
26
36
|
refreshSignalRef.current = refreshSignal;
|
|
27
37
|
if (logic.config === currentLogic.config) {
|
|
28
|
-
currentLogic
|
|
38
|
+
if (isStateMachine(logic) && isStateMachine(currentLogic)) {
|
|
39
|
+
currentLogic.sources = logic.sources;
|
|
40
|
+
}
|
|
29
41
|
return;
|
|
30
42
|
}
|
|
31
43
|
});
|
|
@@ -71,7 +83,7 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
71
83
|
if (!observerOrListener) {
|
|
72
84
|
return;
|
|
73
85
|
}
|
|
74
|
-
const sub = actorRef.subscribe(
|
|
86
|
+
const sub = actorRef.subscribe(_toObserver(observerOrListener));
|
|
75
87
|
return () => {
|
|
76
88
|
sub.unsubscribe();
|
|
77
89
|
};
|
|
@@ -113,12 +125,8 @@ function createActorContext(actorLogic, actorOptions) {
|
|
|
113
125
|
function Provider({
|
|
114
126
|
children,
|
|
115
127
|
logic: providedLogic = actorLogic,
|
|
116
|
-
machine,
|
|
117
128
|
options: providedOptions
|
|
118
129
|
}) {
|
|
119
|
-
if (machine) {
|
|
120
|
-
throw new Error(`The "machine" prop has been deprecated. Please use "logic" instead.`);
|
|
121
|
-
}
|
|
122
130
|
const actor = useActorRef(providedLogic, {
|
|
123
131
|
...actorOptions,
|
|
124
132
|
...providedOptions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xstate/react",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.6",
|
|
4
4
|
"description": "XState tools for React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -54,12 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
57
|
-
"xstate": "^6.0.0-alpha.
|
|
58
|
-
},
|
|
59
|
-
"peerDependenciesMeta": {
|
|
60
|
-
"xstate": {
|
|
61
|
-
"optional": true
|
|
62
|
-
}
|
|
57
|
+
"xstate": "^6.0.0-alpha.70"
|
|
63
58
|
},
|
|
64
59
|
"dependencies": {
|
|
65
60
|
"use-isomorphic-layout-effect": "^1.1.2",
|
|
@@ -74,7 +69,7 @@
|
|
|
74
69
|
"react-dom": "^19.0.0",
|
|
75
70
|
"rxjs": "^7.8.1",
|
|
76
71
|
"zod": "^3.25.51",
|
|
77
|
-
"xstate": "^6.0.0-alpha.
|
|
72
|
+
"xstate": "^6.0.0-alpha.70"
|
|
78
73
|
},
|
|
79
74
|
"scripts": {}
|
|
80
75
|
}
|