@xstate/react 7.0.0-alpha.6 → 7.0.0-alpha.7
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/declarations/src/createActorContext.d.ts +1 -0
- package/dist/declarations/src/shallowEqual.d.ts +1 -0
- package/dist/declarations/src/useActor.d.ts +1 -0
- package/dist/declarations/src/useActorRef.d.ts +1 -0
- package/dist/declarations/src/useMachine.d.ts +6 -1
- package/dist/declarations/src/useSelector.d.ts +1 -0
- package/dist/xstate-react.cjs.js +14 -1
- package/dist/xstate-react.development.cjs.js +14 -1
- package/dist/xstate-react.development.esm.js +14 -1
- package/dist/xstate-react.esm.js +14 -1
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Actor, ActorOptions, AnyActorLogic, SnapshotFrom } from 'xstate';
|
|
3
|
+
/** @public */
|
|
3
4
|
export declare function createActorContext<TLogic extends AnyActorLogic>(actorLogic: TLogic, actorOptions?: ActorOptions<TLogic>): {
|
|
4
5
|
useSelector: <T>(selector: (snapshot: SnapshotFrom<TLogic>) => T, compare?: (a: T, b: T) => boolean) => T;
|
|
5
6
|
useActorRef: () => Actor<TLogic>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Actor, ActorOptions, AnyActorLogic, SnapshotFrom, type ConditionalRequired, type IsNotNever, type RequiredActorOptionsKeys, type RequiredActorOptionsFor } from 'xstate';
|
|
2
|
+
/** @public */
|
|
2
3
|
export declare function useActor<TLogic extends AnyActorLogic>(logic: TLogic, ...[options]: ConditionalRequired<[
|
|
3
4
|
options?: ActorOptions<TLogic> & RequiredActorOptionsFor<TLogic>
|
|
4
5
|
], IsNotNever<RequiredActorOptionsKeys<TLogic>>>): [SnapshotFrom<TLogic>, Actor<TLogic>['send'], Actor<TLogic>];
|
|
@@ -3,6 +3,7 @@ export declare function useIdleActorRef<TLogic extends AnyActorLogic>(logic: TLo
|
|
|
3
3
|
options?: ActorOptions<TLogic> & RequiredActorOptionsFor<TLogic>
|
|
4
4
|
], IsNotNever<RequiredActorOptionsKeys<TLogic>>>): [Actor<TLogic>, (actorRef: Actor<TLogic>) => void];
|
|
5
5
|
export declare function useActorLifecycle<TLogic extends AnyActorLogic>(actorRef: Actor<TLogic>, setActorRef: (actorRef: Actor<TLogic>) => void, createReplacement: () => Actor<TLogic>): void;
|
|
6
|
+
/** @public */
|
|
6
7
|
export declare function useActorRef<TLogic extends AnyActorLogic>(machine: TLogic, ...[options, observerOrListener]: IsNotNever<RequiredActorOptionsKeys<TLogic>> extends true ? [
|
|
7
8
|
options: ActorOptions<TLogic> & RequiredActorOptionsFor<TLogic>,
|
|
8
9
|
observerOrListener?: Observer<SnapshotFrom<TLogic>> | ((value: SnapshotFrom<TLogic>) => void)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Actor, ActorOptions, AnyStateMachine, StateFrom, type ConditionalRequired, type IsNotNever, type RequiredActorOptionsKeys, type RequiredActorOptionsFor } from 'xstate';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* @alias useActor
|
|
4
|
+
*
|
|
5
|
+
* @deprecated Use `useActor(machine, options)`.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
3
8
|
export declare function useMachine<TMachine extends AnyStateMachine>(machine: TMachine, ...[options]: ConditionalRequired<[
|
|
4
9
|
options?: ActorOptions<TMachine> & RequiredActorOptionsFor<TMachine>
|
|
5
10
|
], IsNotNever<RequiredActorOptionsKeys<TMachine>>>): [StateFrom<TMachine>, Actor<TMachine>['send'], Actor<TMachine>];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AnyActorRef } from 'xstate';
|
|
2
|
+
/** @public */
|
|
2
3
|
export declare function useSelector<TActor extends Pick<AnyActorRef, 'subscribe' | 'getSnapshot'> | undefined, T>(actor: TActor, selector: (snapshot: TActor extends {
|
|
3
4
|
getSnapshot(): infer TSnapshot;
|
|
4
5
|
} ? TSnapshot : undefined) => T, compare?: (a: T, b: T) => boolean): T;
|
package/dist/xstate-react.cjs.js
CHANGED
|
@@ -103,6 +103,8 @@ function useActorLifecycle(actorRef, setActorRef, createReplacement) {
|
|
|
103
103
|
};
|
|
104
104
|
}, [actorRef]);
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
/** @public */
|
|
106
108
|
function useActorRef(machine, ...[options, observerOrListener]) {
|
|
107
109
|
const [actorRef, setActorRef] = useIdleActorRef(machine, options);
|
|
108
110
|
React.useEffect(() => {
|
|
@@ -121,6 +123,8 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
121
123
|
function defaultCompare(a, b) {
|
|
122
124
|
return a === b;
|
|
123
125
|
}
|
|
126
|
+
|
|
127
|
+
/** @public */
|
|
124
128
|
function useSelector(actor, selector, compare = defaultCompare) {
|
|
125
129
|
const subscribe = React.useCallback(handleStoreChange => {
|
|
126
130
|
if (!actor) {
|
|
@@ -145,6 +149,7 @@ function useSelector(actor, selector, compare = defaultCompare) {
|
|
|
145
149
|
return selectedSnapshot;
|
|
146
150
|
}
|
|
147
151
|
|
|
152
|
+
/** @public */
|
|
148
153
|
function createActorContext(actorLogic, actorOptions) {
|
|
149
154
|
const ReactContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
150
155
|
const OriginalProvider = ReactContext.Provider;
|
|
@@ -191,6 +196,8 @@ function is(x, y) {
|
|
|
191
196
|
return x !== x && y !== y;
|
|
192
197
|
}
|
|
193
198
|
}
|
|
199
|
+
|
|
200
|
+
/** @public */
|
|
194
201
|
function shallowEqual(objA, objB) {
|
|
195
202
|
if (is(objA, objB)) return true;
|
|
196
203
|
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
@@ -207,6 +214,7 @@ function shallowEqual(objA, objB) {
|
|
|
207
214
|
return true;
|
|
208
215
|
}
|
|
209
216
|
|
|
217
|
+
/** @public */
|
|
210
218
|
function useActor(logic, ...[options]) {
|
|
211
219
|
const [actorRef, setActorRef] = useIdleActorRef(logic, options);
|
|
212
220
|
const getSnapshot = React.useCallback(() => {
|
|
@@ -230,7 +238,12 @@ function useActor(logic, ...[options]) {
|
|
|
230
238
|
return [actorSnapshot, actorRef.send, actorRef];
|
|
231
239
|
}
|
|
232
240
|
|
|
233
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* @alias useActor
|
|
243
|
+
*
|
|
244
|
+
* @deprecated Use `useActor(machine, options)`.
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
234
247
|
function useMachine(machine, ...[options]) {
|
|
235
248
|
return useActor(machine, options);
|
|
236
249
|
}
|
|
@@ -113,6 +113,8 @@ function useActorLifecycle(actorRef, setActorRef, createReplacement) {
|
|
|
113
113
|
};
|
|
114
114
|
}, [actorRef]);
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
/** @public */
|
|
116
118
|
function useActorRef(machine, ...[options, observerOrListener]) {
|
|
117
119
|
const [actorRef, setActorRef] = useIdleActorRef(machine, options);
|
|
118
120
|
React.useEffect(() => {
|
|
@@ -131,6 +133,8 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
131
133
|
function defaultCompare(a, b) {
|
|
132
134
|
return a === b;
|
|
133
135
|
}
|
|
136
|
+
|
|
137
|
+
/** @public */
|
|
134
138
|
function useSelector(actor, selector, compare = defaultCompare) {
|
|
135
139
|
const subscribe = React.useCallback(handleStoreChange => {
|
|
136
140
|
if (!actor) {
|
|
@@ -155,6 +159,7 @@ function useSelector(actor, selector, compare = defaultCompare) {
|
|
|
155
159
|
return selectedSnapshot;
|
|
156
160
|
}
|
|
157
161
|
|
|
162
|
+
/** @public */
|
|
158
163
|
function createActorContext(actorLogic, actorOptions) {
|
|
159
164
|
const ReactContext = /*#__PURE__*/React__namespace.createContext(null);
|
|
160
165
|
const OriginalProvider = ReactContext.Provider;
|
|
@@ -201,6 +206,8 @@ function is(x, y) {
|
|
|
201
206
|
return x !== x && y !== y;
|
|
202
207
|
}
|
|
203
208
|
}
|
|
209
|
+
|
|
210
|
+
/** @public */
|
|
204
211
|
function shallowEqual(objA, objB) {
|
|
205
212
|
if (is(objA, objB)) return true;
|
|
206
213
|
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
@@ -217,6 +224,7 @@ function shallowEqual(objA, objB) {
|
|
|
217
224
|
return true;
|
|
218
225
|
}
|
|
219
226
|
|
|
227
|
+
/** @public */
|
|
220
228
|
function useActor(logic, ...[options]) {
|
|
221
229
|
if (!!logic && 'send' in logic && typeof logic.send === 'function') {
|
|
222
230
|
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.`);
|
|
@@ -243,7 +251,12 @@ function useActor(logic, ...[options]) {
|
|
|
243
251
|
return [actorSnapshot, actorRef.send, actorRef];
|
|
244
252
|
}
|
|
245
253
|
|
|
246
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* @alias useActor
|
|
256
|
+
*
|
|
257
|
+
* @deprecated Use `useActor(machine, options)`.
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
247
260
|
function useMachine(machine, ...[options]) {
|
|
248
261
|
return useActor(machine, options);
|
|
249
262
|
}
|
|
@@ -87,6 +87,8 @@ function useActorLifecycle(actorRef, setActorRef, createReplacement) {
|
|
|
87
87
|
};
|
|
88
88
|
}, [actorRef]);
|
|
89
89
|
}
|
|
90
|
+
|
|
91
|
+
/** @public */
|
|
90
92
|
function useActorRef(machine, ...[options, observerOrListener]) {
|
|
91
93
|
const [actorRef, setActorRef] = useIdleActorRef(machine, options);
|
|
92
94
|
useEffect(() => {
|
|
@@ -105,6 +107,8 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
105
107
|
function defaultCompare(a, b) {
|
|
106
108
|
return a === b;
|
|
107
109
|
}
|
|
110
|
+
|
|
111
|
+
/** @public */
|
|
108
112
|
function useSelector(actor, selector, compare = defaultCompare) {
|
|
109
113
|
const subscribe = useCallback(handleStoreChange => {
|
|
110
114
|
if (!actor) {
|
|
@@ -129,6 +133,7 @@ function useSelector(actor, selector, compare = defaultCompare) {
|
|
|
129
133
|
return selectedSnapshot;
|
|
130
134
|
}
|
|
131
135
|
|
|
136
|
+
/** @public */
|
|
132
137
|
function createActorContext(actorLogic, actorOptions) {
|
|
133
138
|
const ReactContext = /*#__PURE__*/React.createContext(null);
|
|
134
139
|
const OriginalProvider = ReactContext.Provider;
|
|
@@ -175,6 +180,8 @@ function is(x, y) {
|
|
|
175
180
|
return x !== x && y !== y;
|
|
176
181
|
}
|
|
177
182
|
}
|
|
183
|
+
|
|
184
|
+
/** @public */
|
|
178
185
|
function shallowEqual(objA, objB) {
|
|
179
186
|
if (is(objA, objB)) return true;
|
|
180
187
|
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
@@ -191,6 +198,7 @@ function shallowEqual(objA, objB) {
|
|
|
191
198
|
return true;
|
|
192
199
|
}
|
|
193
200
|
|
|
201
|
+
/** @public */
|
|
194
202
|
function useActor(logic, ...[options]) {
|
|
195
203
|
if (!!logic && 'send' in logic && typeof logic.send === 'function') {
|
|
196
204
|
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.`);
|
|
@@ -217,7 +225,12 @@ function useActor(logic, ...[options]) {
|
|
|
217
225
|
return [actorSnapshot, actorRef.send, actorRef];
|
|
218
226
|
}
|
|
219
227
|
|
|
220
|
-
/**
|
|
228
|
+
/**
|
|
229
|
+
* @alias useActor
|
|
230
|
+
*
|
|
231
|
+
* @deprecated Use `useActor(machine, options)`.
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
221
234
|
function useMachine(machine, ...[options]) {
|
|
222
235
|
return useActor(machine, options);
|
|
223
236
|
}
|
package/dist/xstate-react.esm.js
CHANGED
|
@@ -77,6 +77,8 @@ function useActorLifecycle(actorRef, setActorRef, createReplacement) {
|
|
|
77
77
|
};
|
|
78
78
|
}, [actorRef]);
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
/** @public */
|
|
80
82
|
function useActorRef(machine, ...[options, observerOrListener]) {
|
|
81
83
|
const [actorRef, setActorRef] = useIdleActorRef(machine, options);
|
|
82
84
|
useEffect(() => {
|
|
@@ -95,6 +97,8 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
95
97
|
function defaultCompare(a, b) {
|
|
96
98
|
return a === b;
|
|
97
99
|
}
|
|
100
|
+
|
|
101
|
+
/** @public */
|
|
98
102
|
function useSelector(actor, selector, compare = defaultCompare) {
|
|
99
103
|
const subscribe = useCallback(handleStoreChange => {
|
|
100
104
|
if (!actor) {
|
|
@@ -119,6 +123,7 @@ function useSelector(actor, selector, compare = defaultCompare) {
|
|
|
119
123
|
return selectedSnapshot;
|
|
120
124
|
}
|
|
121
125
|
|
|
126
|
+
/** @public */
|
|
122
127
|
function createActorContext(actorLogic, actorOptions) {
|
|
123
128
|
const ReactContext = /*#__PURE__*/React.createContext(null);
|
|
124
129
|
const OriginalProvider = ReactContext.Provider;
|
|
@@ -165,6 +170,8 @@ function is(x, y) {
|
|
|
165
170
|
return x !== x && y !== y;
|
|
166
171
|
}
|
|
167
172
|
}
|
|
173
|
+
|
|
174
|
+
/** @public */
|
|
168
175
|
function shallowEqual(objA, objB) {
|
|
169
176
|
if (is(objA, objB)) return true;
|
|
170
177
|
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
@@ -181,6 +188,7 @@ function shallowEqual(objA, objB) {
|
|
|
181
188
|
return true;
|
|
182
189
|
}
|
|
183
190
|
|
|
191
|
+
/** @public */
|
|
184
192
|
function useActor(logic, ...[options]) {
|
|
185
193
|
const [actorRef, setActorRef] = useIdleActorRef(logic, options);
|
|
186
194
|
const getSnapshot = useCallback(() => {
|
|
@@ -204,7 +212,12 @@ function useActor(logic, ...[options]) {
|
|
|
204
212
|
return [actorSnapshot, actorRef.send, actorRef];
|
|
205
213
|
}
|
|
206
214
|
|
|
207
|
-
/**
|
|
215
|
+
/**
|
|
216
|
+
* @alias useActor
|
|
217
|
+
*
|
|
218
|
+
* @deprecated Use `useActor(machine, options)`.
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
208
221
|
function useMachine(machine, ...[options]) {
|
|
209
222
|
return useActor(machine, options);
|
|
210
223
|
}
|
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.7",
|
|
4
4
|
"description": "XState tools for React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -54,7 +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.
|
|
57
|
+
"xstate": "^6.0.0-alpha.73"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"use-isomorphic-layout-effect": "^1.1.2",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"react-dom": "^19.0.0",
|
|
70
70
|
"rxjs": "^7.8.1",
|
|
71
71
|
"zod": "^3.25.51",
|
|
72
|
-
"xstate": "^6.0.0-alpha.
|
|
72
|
+
"xstate": "^6.0.0-alpha.73"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {}
|
|
75
75
|
}
|