@xstate/react 4.0.0-alpha.1 → 4.0.0-beta.3
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 +15 -0
- package/dist/declarations/src/index.d.ts +7 -6
- package/dist/declarations/src/types.d.ts +3 -3
- package/dist/declarations/src/useInterpret.d.ts +5 -6
- package/dist/declarations/src/useMachine.d.ts +6 -17
- package/dist/declarations/src/useSpawn.d.ts +2 -2
- package/dist/{useConstant-94bfdbb5.esm.js → useConstant-0013a606.esm.js} +21 -24
- package/dist/{useConstant-eeb49d3f.cjs.prod.js → useConstant-c09b427a.cjs.prod.js} +0 -2
- package/dist/{useConstant-644f0e11.cjs.dev.js → useConstant-ff65b597.cjs.dev.js} +21 -24
- package/dist/xstate-react.cjs.dev.js +119 -75
- package/dist/xstate-react.cjs.prod.js +117 -71
- package/dist/xstate-react.esm.js +120 -77
- package/fsm/dist/xstate-react-fsm.cjs.dev.js +23 -41
- package/fsm/dist/xstate-react-fsm.cjs.prod.js +42 -59
- package/fsm/dist/xstate-react-fsm.esm.js +22 -40
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as _slicedToArray, u as useConstant } from '../../dist/useConstant-
|
|
1
|
+
import { _ as _slicedToArray, u as useConstant } from '../../dist/useConstant-0013a606.esm.js';
|
|
2
2
|
import { interpret, createMachine, InterpreterStatus } from '@xstate/fsm';
|
|
3
3
|
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
4
4
|
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
|
|
@@ -7,50 +7,35 @@ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/w
|
|
|
7
7
|
function identity(a) {
|
|
8
8
|
return a;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
var getServiceState = function getServiceState(service) {
|
|
12
|
-
var currentValue;
|
|
13
|
-
service.subscribe(function (state) {
|
|
14
|
-
currentValue = state;
|
|
15
|
-
}).unsubscribe();
|
|
16
|
-
return currentValue;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
10
|
function useMachine(stateMachine, options) {
|
|
20
11
|
var persistedStateRef = useRef();
|
|
21
|
-
|
|
22
12
|
if (process.env.NODE_ENV !== 'production') {
|
|
23
13
|
var _useState = useState(stateMachine),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
15
|
+
initialMachine = _useState2[0];
|
|
27
16
|
if (stateMachine !== initialMachine) {
|
|
28
17
|
console.warn('Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.\n' + 'Please make sure that you pass the same Machine as argument each time.');
|
|
29
18
|
}
|
|
30
19
|
}
|
|
31
|
-
|
|
32
20
|
var _useConstant = useConstant(function () {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
_useConstant2 = _slicedToArray(_useConstant, 2),
|
|
50
|
-
service = _useConstant2[0],
|
|
51
|
-
queue = _useConstant2[1]; // TODO: consider using `useInsertionEffect` if available
|
|
52
|
-
|
|
21
|
+
var queue = [];
|
|
22
|
+
var service = interpret(createMachine(stateMachine.config, options ? options : stateMachine._options));
|
|
23
|
+
var send = service.send;
|
|
24
|
+
service.send = function (event) {
|
|
25
|
+
if (service.status === InterpreterStatus.NotStarted) {
|
|
26
|
+
queue.push(event);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
send(event);
|
|
30
|
+
persistedStateRef.current = service.state;
|
|
31
|
+
};
|
|
32
|
+
return [service, queue];
|
|
33
|
+
}),
|
|
34
|
+
_useConstant2 = _slicedToArray(_useConstant, 2),
|
|
35
|
+
service = _useConstant2[0],
|
|
36
|
+
queue = _useConstant2[1];
|
|
53
37
|
|
|
38
|
+
// TODO: consider using `useInsertionEffect` if available
|
|
54
39
|
useIsomorphicLayoutEffect(function () {
|
|
55
40
|
if (options) {
|
|
56
41
|
service._machine._options = options;
|
|
@@ -67,19 +52,16 @@ function useMachine(stateMachine, options) {
|
|
|
67
52
|
}, []);
|
|
68
53
|
return useServiceResult;
|
|
69
54
|
}
|
|
70
|
-
|
|
71
55
|
var isEqual = function isEqual(_prevState, nextState) {
|
|
72
56
|
return nextState.changed === false;
|
|
73
57
|
};
|
|
74
|
-
|
|
75
58
|
function useService(service) {
|
|
76
59
|
var getSnapshot = useCallback(function () {
|
|
77
|
-
return
|
|
60
|
+
return service.state;
|
|
78
61
|
}, [service]);
|
|
79
62
|
var subscribe = useCallback(function (handleStoreChange) {
|
|
80
63
|
var _service$subscribe = service.subscribe(handleStoreChange),
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
unsubscribe = _service$subscribe.unsubscribe;
|
|
83
65
|
return unsubscribe;
|
|
84
66
|
}, [service]);
|
|
85
67
|
var storeSnapshot = useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xstate/react",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.3",
|
|
4
4
|
"description": "XState tools for React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"url": "https://github.com/statelyai/xstate/issues"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@xstate/fsm": "^3.0.0-
|
|
46
|
+
"@xstate/fsm": "^3.0.0-beta.2",
|
|
47
47
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
48
|
-
"xstate": "^5.0.0-
|
|
48
|
+
"xstate": "^5.0.0-beta.7"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@xstate/fsm": {
|
|
@@ -60,17 +60,17 @@
|
|
|
60
60
|
"use-sync-external-store": "^1.0.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@testing-library/react": "^13.
|
|
63
|
+
"@testing-library/react": "^13.4.0",
|
|
64
64
|
"@types/jsdom": "^12.2.3",
|
|
65
65
|
"@types/react": "^17.0.43",
|
|
66
66
|
"@types/react-dom": "^17.0.14",
|
|
67
67
|
"@types/use-sync-external-store": "^0.0.3",
|
|
68
|
-
"@xstate/fsm": "3.0.0-
|
|
68
|
+
"@xstate/fsm": "3.0.0-beta.2",
|
|
69
69
|
"jsdom": "^14.0.0",
|
|
70
70
|
"jsdom-global": "^3.0.2",
|
|
71
71
|
"react": "^18.0.0",
|
|
72
72
|
"react-dom": "^18.0.0",
|
|
73
|
-
"xstate": "5.0.0-
|
|
73
|
+
"xstate": "5.0.0-beta.7"
|
|
74
74
|
},
|
|
75
75
|
"preconstruct": {
|
|
76
76
|
"entrypoints": [
|