@xstate/react 4.0.0-beta.8 → 4.0.0-beta.9
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/README.md +0 -8
- package/dist/declarations/src/createActorContext.d.ts +4 -4
- package/dist/declarations/src/useActor.d.ts +2 -2
- package/dist/declarations/src/useActorRef.d.ts +5 -5
- package/dist/declarations/src/useMachine.d.ts +2 -2
- package/dist/xstate-react.cjs.js +14 -5
- package/dist/xstate-react.development.cjs.js +14 -5
- package/dist/xstate-react.development.esm.js +14 -5
- package/dist/xstate-react.esm.js +14 -5
- package/package.json +4 -30
- package/dist/declarations/src/fsm.d.ts +0 -3
- package/dist/useConstant-2ee82f84.cjs.js +0 -35
- package/dist/useConstant-ae6dceac.development.cjs.js +0 -35
- package/dist/useConstant-bac83df4.development.esm.js +0 -13
- package/dist/useConstant-c7ec0fdd.esm.js +0 -13
- package/fsm/dist/xstate-react-fsm.cjs.d.mts +0 -2
- package/fsm/dist/xstate-react-fsm.cjs.d.mts.map +0 -1
- package/fsm/dist/xstate-react-fsm.cjs.d.ts +0 -2
- package/fsm/dist/xstate-react-fsm.cjs.d.ts.map +0 -1
- package/fsm/dist/xstate-react-fsm.cjs.js +0 -68
- package/fsm/dist/xstate-react-fsm.cjs.mjs +0 -4
- package/fsm/dist/xstate-react-fsm.development.cjs.js +0 -74
- package/fsm/dist/xstate-react-fsm.development.cjs.mjs +0 -4
- package/fsm/dist/xstate-react-fsm.development.esm.js +0 -65
- package/fsm/dist/xstate-react-fsm.esm.js +0 -59
- package/fsm/package.json +0 -4
package/README.md
CHANGED
|
@@ -21,14 +21,6 @@ npm i xstate @xstate/react
|
|
|
21
21
|
|
|
22
22
|
By using the global variable `XStateReact`
|
|
23
23
|
|
|
24
|
-
or
|
|
25
|
-
|
|
26
|
-
```html
|
|
27
|
-
<script src="https://unpkg.com/@xstate/react/dist/xstate-react-fsm.umd.min.js"></script>
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
By using the global variable `XStateReactFSM`
|
|
31
|
-
|
|
32
24
|
2. Import the `useMachine` hook:
|
|
33
25
|
|
|
34
26
|
```js
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ActorRefFrom, AnyStateMachine, SnapshotFrom,
|
|
3
|
-
type ToMachinesWithProvidedImplementations<TMachine extends AnyStateMachine> = TMachine extends StateMachine<infer TContext, infer TEvent, infer TAction, infer
|
|
4
|
-
export declare function createActorContext<TLogic extends AnyActorLogic>(actorLogic: TLogic, interpreterOptions?:
|
|
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;
|
|
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>;
|
|
7
7
|
Provider: (props: {
|
|
8
8
|
children: React.ReactNode;
|
|
9
|
-
options?:
|
|
9
|
+
options?: ActorOptions<TLogic>;
|
|
10
10
|
} & (TLogic extends AnyStateMachine ? AreAllImplementationsAssumedToBeProvided<TLogic['__TResolvedTypesMeta']> extends true ? {
|
|
11
11
|
logic?: TLogic;
|
|
12
12
|
} : {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ActorRefFrom, AnyActorLogic,
|
|
2
|
-
export declare function useActor<TLogic extends AnyActorLogic>(logic: TLogic, options?:
|
|
1
|
+
import { ActorRefFrom, AnyActorLogic, ActorOptions, SnapshotFrom } from 'xstate';
|
|
2
|
+
export declare function useActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: ActorOptions<TLogic>): [SnapshotFrom<TLogic>, ActorRefFrom<TLogic>['send'], ActorRefFrom<TLogic>];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { AnyActorLogic,
|
|
2
|
-
export declare function useIdleInterpreter(machine: AnyActorLogic, options: Partial<
|
|
1
|
+
import { AnyActorLogic, AnyActor, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, InternalMachineImplementations, ActorRefFrom, ActorOptions, Observer, StateFrom, SnapshotFrom, TODO } from 'xstate';
|
|
2
|
+
export declare function useIdleInterpreter(machine: AnyActorLogic, options: Partial<ActorOptions<AnyActorLogic>>): AnyActor;
|
|
3
3
|
type RestParams<TLogic extends AnyActorLogic> = TLogic extends AnyStateMachine ? AreAllImplementationsAssumedToBeProvided<TLogic['__TResolvedTypesMeta']> extends false ? [
|
|
4
|
-
options:
|
|
4
|
+
options: ActorOptions<TLogic> & InternalMachineImplementations<TLogic['__TContext'], TLogic['__TEvent'], TODO, TODO, TODO, TLogic['__TResolvedTypesMeta'], true>,
|
|
5
5
|
observerOrListener?: Observer<StateFrom<TLogic>> | ((value: StateFrom<TLogic>) => void)
|
|
6
6
|
] : [
|
|
7
|
-
options?:
|
|
7
|
+
options?: ActorOptions<TLogic> & InternalMachineImplementations<TLogic['__TContext'], TLogic['__TEvent'], TODO, TODO, TODO, TLogic['__TResolvedTypesMeta']>,
|
|
8
8
|
observerOrListener?: Observer<StateFrom<TLogic>> | ((value: StateFrom<TLogic>) => void)
|
|
9
9
|
] : [
|
|
10
|
-
options?:
|
|
10
|
+
options?: ActorOptions<TLogic>,
|
|
11
11
|
observerOrListener?: Observer<SnapshotFrom<TLogic>> | ((value: SnapshotFrom<TLogic>) => void)
|
|
12
12
|
];
|
|
13
13
|
export declare function useActorRef<TLogic extends AnyActorLogic>(machine: TLogic, ...[options, observerOrListener]: RestParams<TLogic>): ActorRefFrom<TLogic>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ActorRefFrom, AnyStateMachine, AreAllImplementationsAssumedToBeProvided,
|
|
1
|
+
import { ActorRefFrom, AnyStateMachine, AreAllImplementationsAssumedToBeProvided, ActorOptions, MissingImplementationsError, StateFrom } from 'xstate';
|
|
2
2
|
/**
|
|
3
3
|
*
|
|
4
4
|
* @deprecated Use `useActor(...)` instead.
|
|
5
5
|
*/
|
|
6
|
-
export declare function useMachine<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : MissingImplementationsError<TMachine['__TResolvedTypesMeta']>, options?:
|
|
6
|
+
export declare function useMachine<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : MissingImplementationsError<TMachine['__TResolvedTypesMeta']>, options?: ActorOptions<TMachine>): [
|
|
7
7
|
StateFrom<TMachine>,
|
|
8
8
|
ActorRefFrom<TMachine>['send'],
|
|
9
9
|
ActorRefFrom<TMachine>
|
package/dist/xstate-react.cjs.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var shim = require('use-sync-external-store/shim');
|
|
7
7
|
var xstate = require('xstate');
|
|
8
|
-
var useConstant = require('./useConstant-2ee82f84.cjs.js');
|
|
9
8
|
var useIsomorphicLayoutEffect = require('use-isomorphic-layout-effect');
|
|
10
9
|
require('xstate/actors');
|
|
11
10
|
var withSelector = require('use-sync-external-store/shim/with-selector');
|
|
@@ -33,9 +32,19 @@ function _interopNamespace(e) {
|
|
|
33
32
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
34
33
|
var useIsomorphicLayoutEffect__default = /*#__PURE__*/_interopDefault(useIsomorphicLayoutEffect);
|
|
35
34
|
|
|
35
|
+
function useConstant(fn) {
|
|
36
|
+
const ref = React__namespace.useRef();
|
|
37
|
+
if (!ref.current) {
|
|
38
|
+
ref.current = {
|
|
39
|
+
v: fn()
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return ref.current.v;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
function useIdleInterpreter(machine, options) {
|
|
37
|
-
const actorRef = useConstant
|
|
38
|
-
return xstate.
|
|
46
|
+
const actorRef = useConstant(() => {
|
|
47
|
+
return xstate.createActor(machine, options);
|
|
39
48
|
});
|
|
40
49
|
|
|
41
50
|
// TODO: consider using `useAsapEffect` that would do this in `useInsertionEffect` is that's available
|
|
@@ -59,7 +68,7 @@ function useActorRef(machine, ...[options = {}, observerOrListener]) {
|
|
|
59
68
|
actorRef.start();
|
|
60
69
|
return () => {
|
|
61
70
|
actorRef.stop();
|
|
62
|
-
actorRef.status = xstate.
|
|
71
|
+
actorRef.status = xstate.ActorStatus.NotStarted;
|
|
63
72
|
actorRef._initState();
|
|
64
73
|
};
|
|
65
74
|
}, []);
|
|
@@ -82,7 +91,7 @@ function useActor(logic, options = {}) {
|
|
|
82
91
|
actorRef.start();
|
|
83
92
|
return () => {
|
|
84
93
|
actorRef.stop();
|
|
85
|
-
actorRef.status = xstate.
|
|
94
|
+
actorRef.status = xstate.ActorStatus.NotStarted;
|
|
86
95
|
actorRef._initState();
|
|
87
96
|
};
|
|
88
97
|
}, [actorRef]);
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var shim = require('use-sync-external-store/shim');
|
|
7
7
|
var xstate = require('xstate');
|
|
8
|
-
var useConstant = require('./useConstant-ae6dceac.development.cjs.js');
|
|
9
8
|
var useIsomorphicLayoutEffect = require('use-isomorphic-layout-effect');
|
|
10
9
|
var actors = require('xstate/actors');
|
|
11
10
|
var withSelector = require('use-sync-external-store/shim/with-selector');
|
|
@@ -33,6 +32,16 @@ function _interopNamespace(e) {
|
|
|
33
32
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
34
33
|
var useIsomorphicLayoutEffect__default = /*#__PURE__*/_interopDefault(useIsomorphicLayoutEffect);
|
|
35
34
|
|
|
35
|
+
function useConstant(fn) {
|
|
36
|
+
const ref = React__namespace.useRef();
|
|
37
|
+
if (!ref.current) {
|
|
38
|
+
ref.current = {
|
|
39
|
+
v: fn()
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return ref.current.v;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
function useIdleInterpreter(machine, options) {
|
|
37
46
|
{
|
|
38
47
|
const [initialMachine] = React.useState(machine);
|
|
@@ -40,8 +49,8 @@ function useIdleInterpreter(machine, options) {
|
|
|
40
49
|
console.warn(`Actor logic has changed between renders. This is not supported and may lead to invalid snapshots.`);
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
|
-
const actorRef = useConstant
|
|
44
|
-
return xstate.
|
|
52
|
+
const actorRef = useConstant(() => {
|
|
53
|
+
return xstate.createActor(machine, options);
|
|
45
54
|
});
|
|
46
55
|
|
|
47
56
|
// TODO: consider using `useAsapEffect` that would do this in `useInsertionEffect` is that's available
|
|
@@ -65,7 +74,7 @@ function useActorRef(machine, ...[options = {}, observerOrListener]) {
|
|
|
65
74
|
actorRef.start();
|
|
66
75
|
return () => {
|
|
67
76
|
actorRef.stop();
|
|
68
|
-
actorRef.status = xstate.
|
|
77
|
+
actorRef.status = xstate.ActorStatus.NotStarted;
|
|
69
78
|
actorRef._initState();
|
|
70
79
|
};
|
|
71
80
|
}, []);
|
|
@@ -91,7 +100,7 @@ function useActor(logic, options = {}) {
|
|
|
91
100
|
actorRef.start();
|
|
92
101
|
return () => {
|
|
93
102
|
actorRef.stop();
|
|
94
|
-
actorRef.status = xstate.
|
|
103
|
+
actorRef.status = xstate.ActorStatus.NotStarted;
|
|
95
104
|
actorRef._initState();
|
|
96
105
|
};
|
|
97
106
|
}, [actorRef]);
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useEffect, useState, useCallback } from 'react';
|
|
3
3
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
4
|
-
import { toObserver,
|
|
5
|
-
import { u as useConstant } from './useConstant-bac83df4.development.esm.js';
|
|
4
|
+
import { toObserver, ActorStatus, createActor } from 'xstate';
|
|
6
5
|
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
|
|
7
6
|
import { isActorRef } from 'xstate/actors';
|
|
8
7
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
9
8
|
|
|
9
|
+
function useConstant(fn) {
|
|
10
|
+
const ref = React.useRef();
|
|
11
|
+
if (!ref.current) {
|
|
12
|
+
ref.current = {
|
|
13
|
+
v: fn()
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return ref.current.v;
|
|
17
|
+
}
|
|
18
|
+
|
|
10
19
|
function useIdleInterpreter(machine, options) {
|
|
11
20
|
{
|
|
12
21
|
const [initialMachine] = useState(machine);
|
|
@@ -15,7 +24,7 @@ function useIdleInterpreter(machine, options) {
|
|
|
15
24
|
}
|
|
16
25
|
}
|
|
17
26
|
const actorRef = useConstant(() => {
|
|
18
|
-
return
|
|
27
|
+
return createActor(machine, options);
|
|
19
28
|
});
|
|
20
29
|
|
|
21
30
|
// TODO: consider using `useAsapEffect` that would do this in `useInsertionEffect` is that's available
|
|
@@ -39,7 +48,7 @@ function useActorRef(machine, ...[options = {}, observerOrListener]) {
|
|
|
39
48
|
actorRef.start();
|
|
40
49
|
return () => {
|
|
41
50
|
actorRef.stop();
|
|
42
|
-
actorRef.status =
|
|
51
|
+
actorRef.status = ActorStatus.NotStarted;
|
|
43
52
|
actorRef._initState();
|
|
44
53
|
};
|
|
45
54
|
}, []);
|
|
@@ -65,7 +74,7 @@ function useActor(logic, options = {}) {
|
|
|
65
74
|
actorRef.start();
|
|
66
75
|
return () => {
|
|
67
76
|
actorRef.stop();
|
|
68
|
-
actorRef.status =
|
|
77
|
+
actorRef.status = ActorStatus.NotStarted;
|
|
69
78
|
actorRef._initState();
|
|
70
79
|
};
|
|
71
80
|
}, [actorRef]);
|
package/dist/xstate-react.esm.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useEffect, useCallback } from 'react';
|
|
3
3
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
4
|
-
import { toObserver,
|
|
5
|
-
import { u as useConstant } from './useConstant-c7ec0fdd.esm.js';
|
|
4
|
+
import { toObserver, ActorStatus, createActor } from 'xstate';
|
|
6
5
|
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
|
|
7
6
|
import 'xstate/actors';
|
|
8
7
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
9
8
|
|
|
9
|
+
function useConstant(fn) {
|
|
10
|
+
const ref = React.useRef();
|
|
11
|
+
if (!ref.current) {
|
|
12
|
+
ref.current = {
|
|
13
|
+
v: fn()
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return ref.current.v;
|
|
17
|
+
}
|
|
18
|
+
|
|
10
19
|
function useIdleInterpreter(machine, options) {
|
|
11
20
|
const actorRef = useConstant(() => {
|
|
12
|
-
return
|
|
21
|
+
return createActor(machine, options);
|
|
13
22
|
});
|
|
14
23
|
|
|
15
24
|
// TODO: consider using `useAsapEffect` that would do this in `useInsertionEffect` is that's available
|
|
@@ -33,7 +42,7 @@ function useActorRef(machine, ...[options = {}, observerOrListener]) {
|
|
|
33
42
|
actorRef.start();
|
|
34
43
|
return () => {
|
|
35
44
|
actorRef.stop();
|
|
36
|
-
actorRef.status =
|
|
45
|
+
actorRef.status = ActorStatus.NotStarted;
|
|
37
46
|
actorRef._initState();
|
|
38
47
|
};
|
|
39
48
|
}, []);
|
|
@@ -56,7 +65,7 @@ function useActor(logic, options = {}) {
|
|
|
56
65
|
actorRef.start();
|
|
57
66
|
return () => {
|
|
58
67
|
actorRef.stop();
|
|
59
|
-
actorRef.status =
|
|
68
|
+
actorRef.status = ActorStatus.NotStarted;
|
|
60
69
|
actorRef._initState();
|
|
61
70
|
};
|
|
62
71
|
}, [actorRef]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xstate/react",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.9",
|
|
4
4
|
"description": "XState tools for React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -18,20 +18,6 @@
|
|
|
18
18
|
"main": "dist/xstate-react.cjs.js",
|
|
19
19
|
"module": "dist/xstate-react.esm.js",
|
|
20
20
|
"exports": {
|
|
21
|
-
"./fsm": {
|
|
22
|
-
"types": {
|
|
23
|
-
"import": "./fsm/dist/xstate-react-fsm.cjs.mjs",
|
|
24
|
-
"default": "./fsm/dist/xstate-react-fsm.cjs.js"
|
|
25
|
-
},
|
|
26
|
-
"development": {
|
|
27
|
-
"module": "./fsm/dist/xstate-react-fsm.development.esm.js",
|
|
28
|
-
"import": "./fsm/dist/xstate-react-fsm.development.cjs.mjs",
|
|
29
|
-
"default": "./fsm/dist/xstate-react-fsm.development.cjs.js"
|
|
30
|
-
},
|
|
31
|
-
"module": "./fsm/dist/xstate-react-fsm.esm.js",
|
|
32
|
-
"import": "./fsm/dist/xstate-react-fsm.cjs.mjs",
|
|
33
|
-
"default": "./fsm/dist/xstate-react-fsm.cjs.js"
|
|
34
|
-
},
|
|
35
21
|
".": {
|
|
36
22
|
"types": {
|
|
37
23
|
"import": "./dist/xstate-react.cjs.mjs",
|
|
@@ -57,8 +43,7 @@
|
|
|
57
43
|
"types": "dist/xstate-react.cjs.d.ts",
|
|
58
44
|
"sideEffects": false,
|
|
59
45
|
"files": [
|
|
60
|
-
"dist"
|
|
61
|
-
"fsm"
|
|
46
|
+
"dist"
|
|
62
47
|
],
|
|
63
48
|
"repository": {
|
|
64
49
|
"type": "git",
|
|
@@ -69,14 +54,10 @@
|
|
|
69
54
|
"url": "https://github.com/statelyai/xstate/issues"
|
|
70
55
|
},
|
|
71
56
|
"peerDependencies": {
|
|
72
|
-
"@xstate/fsm": "^3.0.0-beta.3",
|
|
73
57
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
74
|
-
"xstate": "^5.0.0-beta.
|
|
58
|
+
"xstate": "^5.0.0-beta.28"
|
|
75
59
|
},
|
|
76
60
|
"peerDependenciesMeta": {
|
|
77
|
-
"@xstate/fsm": {
|
|
78
|
-
"optional": true
|
|
79
|
-
},
|
|
80
61
|
"xstate": {
|
|
81
62
|
"optional": true
|
|
82
63
|
}
|
|
@@ -91,17 +72,10 @@
|
|
|
91
72
|
"@types/react": "^17.0.43",
|
|
92
73
|
"@types/react-dom": "^17.0.14",
|
|
93
74
|
"@types/use-sync-external-store": "^0.0.3",
|
|
94
|
-
"@xstate/fsm": "3.0.0-beta.3",
|
|
95
75
|
"jsdom": "^14.0.0",
|
|
96
76
|
"jsdom-global": "^3.0.2",
|
|
97
77
|
"react": "^18.0.0",
|
|
98
78
|
"react-dom": "^18.0.0",
|
|
99
|
-
"xstate": "5.0.0-beta.
|
|
100
|
-
},
|
|
101
|
-
"preconstruct": {
|
|
102
|
-
"entrypoints": [
|
|
103
|
-
"./index.ts",
|
|
104
|
-
"./fsm.ts"
|
|
105
|
-
]
|
|
79
|
+
"xstate": "5.0.0-beta.28"
|
|
106
80
|
}
|
|
107
81
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { MachineImplementationsFrom, ServiceFrom, StateFrom, StateMachine } from '@xstate/fsm';
|
|
2
|
-
export declare function useMachine<TMachine extends StateMachine.AnyMachine>(stateMachine: TMachine, options?: MachineImplementationsFrom<TMachine>): [StateFrom<TMachine>, ServiceFrom<TMachine>['send'], ServiceFrom<TMachine>];
|
|
3
|
-
export declare function useService<TService extends StateMachine.AnyService>(service: TService): [StateFrom<TService>, TService['send'], TService];
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
|
|
5
|
-
function _interopNamespace(e) {
|
|
6
|
-
if (e && e.__esModule) return e;
|
|
7
|
-
var n = Object.create(null);
|
|
8
|
-
if (e) {
|
|
9
|
-
Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n["default"] = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
24
|
-
|
|
25
|
-
function useConstant(fn) {
|
|
26
|
-
const ref = React__namespace.useRef();
|
|
27
|
-
if (!ref.current) {
|
|
28
|
-
ref.current = {
|
|
29
|
-
v: fn()
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return ref.current.v;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
exports.useConstant = useConstant;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
|
|
5
|
-
function _interopNamespace(e) {
|
|
6
|
-
if (e && e.__esModule) return e;
|
|
7
|
-
var n = Object.create(null);
|
|
8
|
-
if (e) {
|
|
9
|
-
Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n["default"] = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
24
|
-
|
|
25
|
-
function useConstant(fn) {
|
|
26
|
-
const ref = React__namespace.useRef();
|
|
27
|
-
if (!ref.current) {
|
|
28
|
-
ref.current = {
|
|
29
|
-
v: fn()
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return ref.current.v;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
exports.useConstant = useConstant;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"xstate-react-fsm.cjs.d.mts","sourceRoot":"","sources":["../../dist/declarations/src/fsm.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"xstate-react-fsm.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/fsm.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var fsm = require('@xstate/fsm');
|
|
6
|
-
var React = require('react');
|
|
7
|
-
var useIsomorphicLayoutEffect = require('use-isomorphic-layout-effect');
|
|
8
|
-
var withSelector = require('use-sync-external-store/shim/with-selector');
|
|
9
|
-
var useConstant = require('../../dist/useConstant-2ee82f84.cjs.js');
|
|
10
|
-
|
|
11
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
|
-
var useIsomorphicLayoutEffect__default = /*#__PURE__*/_interopDefault(useIsomorphicLayoutEffect);
|
|
14
|
-
|
|
15
|
-
function identity(a) {
|
|
16
|
-
return a;
|
|
17
|
-
}
|
|
18
|
-
function useMachine(stateMachine, options) {
|
|
19
|
-
const persistedStateRef = React.useRef();
|
|
20
|
-
const [service, queue] = useConstant.useConstant(() => {
|
|
21
|
-
const queue = [];
|
|
22
|
-
const service = fsm.interpret(fsm.createMachine(stateMachine.config, options ? options : stateMachine._options));
|
|
23
|
-
const {
|
|
24
|
-
send
|
|
25
|
-
} = service;
|
|
26
|
-
service.send = event => {
|
|
27
|
-
if (service.status === fsm.InterpreterStatus.NotStarted) {
|
|
28
|
-
queue.push(event);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
send(event);
|
|
32
|
-
persistedStateRef.current = service.state;
|
|
33
|
-
};
|
|
34
|
-
return [service, queue];
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// TODO: consider using `useInsertionEffect` if available
|
|
38
|
-
useIsomorphicLayoutEffect__default["default"](() => {
|
|
39
|
-
if (options) {
|
|
40
|
-
service._machine._options = options;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const useServiceResult = useService(service);
|
|
44
|
-
React.useEffect(() => {
|
|
45
|
-
service.start(persistedStateRef.current);
|
|
46
|
-
queue.forEach(service.send);
|
|
47
|
-
persistedStateRef.current = service.state;
|
|
48
|
-
return () => {
|
|
49
|
-
service.stop();
|
|
50
|
-
};
|
|
51
|
-
}, []);
|
|
52
|
-
return useServiceResult;
|
|
53
|
-
}
|
|
54
|
-
const isEqual = (_prevState, nextState) => nextState.changed === false;
|
|
55
|
-
function useService(service) {
|
|
56
|
-
const getSnapshot = React.useCallback(() => service.state, [service]);
|
|
57
|
-
const subscribe = React.useCallback(handleStoreChange => {
|
|
58
|
-
const {
|
|
59
|
-
unsubscribe
|
|
60
|
-
} = service.subscribe(handleStoreChange);
|
|
61
|
-
return unsubscribe;
|
|
62
|
-
}, [service]);
|
|
63
|
-
const storeSnapshot = withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
|
|
64
|
-
return [storeSnapshot, service.send, service];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
exports.useMachine = useMachine;
|
|
68
|
-
exports.useService = useService;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var fsm = require('@xstate/fsm');
|
|
6
|
-
var React = require('react');
|
|
7
|
-
var useIsomorphicLayoutEffect = require('use-isomorphic-layout-effect');
|
|
8
|
-
var withSelector = require('use-sync-external-store/shim/with-selector');
|
|
9
|
-
var useConstant = require('../../dist/useConstant-ae6dceac.development.cjs.js');
|
|
10
|
-
|
|
11
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
|
-
var useIsomorphicLayoutEffect__default = /*#__PURE__*/_interopDefault(useIsomorphicLayoutEffect);
|
|
14
|
-
|
|
15
|
-
function identity(a) {
|
|
16
|
-
return a;
|
|
17
|
-
}
|
|
18
|
-
function useMachine(stateMachine, options) {
|
|
19
|
-
const persistedStateRef = React.useRef();
|
|
20
|
-
{
|
|
21
|
-
const [initialMachine] = React.useState(stateMachine);
|
|
22
|
-
if (stateMachine !== initialMachine) {
|
|
23
|
-
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.');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const [service, queue] = useConstant.useConstant(() => {
|
|
27
|
-
const queue = [];
|
|
28
|
-
const service = fsm.interpret(fsm.createMachine(stateMachine.config, options ? options : stateMachine._options));
|
|
29
|
-
const {
|
|
30
|
-
send
|
|
31
|
-
} = service;
|
|
32
|
-
service.send = event => {
|
|
33
|
-
if (service.status === fsm.InterpreterStatus.NotStarted) {
|
|
34
|
-
queue.push(event);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
send(event);
|
|
38
|
-
persistedStateRef.current = service.state;
|
|
39
|
-
};
|
|
40
|
-
return [service, queue];
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// TODO: consider using `useInsertionEffect` if available
|
|
44
|
-
useIsomorphicLayoutEffect__default["default"](() => {
|
|
45
|
-
if (options) {
|
|
46
|
-
service._machine._options = options;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
const useServiceResult = useService(service);
|
|
50
|
-
React.useEffect(() => {
|
|
51
|
-
service.start(persistedStateRef.current);
|
|
52
|
-
queue.forEach(service.send);
|
|
53
|
-
persistedStateRef.current = service.state;
|
|
54
|
-
return () => {
|
|
55
|
-
service.stop();
|
|
56
|
-
};
|
|
57
|
-
}, []);
|
|
58
|
-
return useServiceResult;
|
|
59
|
-
}
|
|
60
|
-
const isEqual = (_prevState, nextState) => nextState.changed === false;
|
|
61
|
-
function useService(service) {
|
|
62
|
-
const getSnapshot = React.useCallback(() => service.state, [service]);
|
|
63
|
-
const subscribe = React.useCallback(handleStoreChange => {
|
|
64
|
-
const {
|
|
65
|
-
unsubscribe
|
|
66
|
-
} = service.subscribe(handleStoreChange);
|
|
67
|
-
return unsubscribe;
|
|
68
|
-
}, [service]);
|
|
69
|
-
const storeSnapshot = withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
|
|
70
|
-
return [storeSnapshot, service.send, service];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
exports.useMachine = useMachine;
|
|
74
|
-
exports.useService = useService;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { interpret, createMachine, InterpreterStatus } from '@xstate/fsm';
|
|
2
|
-
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
3
|
-
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
|
|
4
|
-
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
5
|
-
import { u as useConstant } from '../../dist/useConstant-bac83df4.development.esm.js';
|
|
6
|
-
|
|
7
|
-
function identity(a) {
|
|
8
|
-
return a;
|
|
9
|
-
}
|
|
10
|
-
function useMachine(stateMachine, options) {
|
|
11
|
-
const persistedStateRef = useRef();
|
|
12
|
-
{
|
|
13
|
-
const [initialMachine] = useState(stateMachine);
|
|
14
|
-
if (stateMachine !== initialMachine) {
|
|
15
|
-
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.');
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
const [service, queue] = useConstant(() => {
|
|
19
|
-
const queue = [];
|
|
20
|
-
const service = interpret(createMachine(stateMachine.config, options ? options : stateMachine._options));
|
|
21
|
-
const {
|
|
22
|
-
send
|
|
23
|
-
} = service;
|
|
24
|
-
service.send = 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
|
-
|
|
35
|
-
// TODO: consider using `useInsertionEffect` if available
|
|
36
|
-
useIsomorphicLayoutEffect(() => {
|
|
37
|
-
if (options) {
|
|
38
|
-
service._machine._options = options;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const useServiceResult = useService(service);
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
service.start(persistedStateRef.current);
|
|
44
|
-
queue.forEach(service.send);
|
|
45
|
-
persistedStateRef.current = service.state;
|
|
46
|
-
return () => {
|
|
47
|
-
service.stop();
|
|
48
|
-
};
|
|
49
|
-
}, []);
|
|
50
|
-
return useServiceResult;
|
|
51
|
-
}
|
|
52
|
-
const isEqual = (_prevState, nextState) => nextState.changed === false;
|
|
53
|
-
function useService(service) {
|
|
54
|
-
const getSnapshot = useCallback(() => service.state, [service]);
|
|
55
|
-
const subscribe = useCallback(handleStoreChange => {
|
|
56
|
-
const {
|
|
57
|
-
unsubscribe
|
|
58
|
-
} = service.subscribe(handleStoreChange);
|
|
59
|
-
return unsubscribe;
|
|
60
|
-
}, [service]);
|
|
61
|
-
const storeSnapshot = useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
|
|
62
|
-
return [storeSnapshot, service.send, service];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { useMachine, useService };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { interpret, createMachine, InterpreterStatus } from '@xstate/fsm';
|
|
2
|
-
import { useRef, useEffect, useCallback } from 'react';
|
|
3
|
-
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect';
|
|
4
|
-
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
5
|
-
import { u as useConstant } from '../../dist/useConstant-c7ec0fdd.esm.js';
|
|
6
|
-
|
|
7
|
-
function identity(a) {
|
|
8
|
-
return a;
|
|
9
|
-
}
|
|
10
|
-
function useMachine(stateMachine, options) {
|
|
11
|
-
const persistedStateRef = useRef();
|
|
12
|
-
const [service, queue] = useConstant(() => {
|
|
13
|
-
const queue = [];
|
|
14
|
-
const service = interpret(createMachine(stateMachine.config, options ? options : stateMachine._options));
|
|
15
|
-
const {
|
|
16
|
-
send
|
|
17
|
-
} = service;
|
|
18
|
-
service.send = event => {
|
|
19
|
-
if (service.status === InterpreterStatus.NotStarted) {
|
|
20
|
-
queue.push(event);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
send(event);
|
|
24
|
-
persistedStateRef.current = service.state;
|
|
25
|
-
};
|
|
26
|
-
return [service, queue];
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// TODO: consider using `useInsertionEffect` if available
|
|
30
|
-
useIsomorphicLayoutEffect(() => {
|
|
31
|
-
if (options) {
|
|
32
|
-
service._machine._options = options;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const useServiceResult = useService(service);
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
service.start(persistedStateRef.current);
|
|
38
|
-
queue.forEach(service.send);
|
|
39
|
-
persistedStateRef.current = service.state;
|
|
40
|
-
return () => {
|
|
41
|
-
service.stop();
|
|
42
|
-
};
|
|
43
|
-
}, []);
|
|
44
|
-
return useServiceResult;
|
|
45
|
-
}
|
|
46
|
-
const isEqual = (_prevState, nextState) => nextState.changed === false;
|
|
47
|
-
function useService(service) {
|
|
48
|
-
const getSnapshot = useCallback(() => service.state, [service]);
|
|
49
|
-
const subscribe = useCallback(handleStoreChange => {
|
|
50
|
-
const {
|
|
51
|
-
unsubscribe
|
|
52
|
-
} = service.subscribe(handleStoreChange);
|
|
53
|
-
return unsubscribe;
|
|
54
|
-
}, [service]);
|
|
55
|
-
const storeSnapshot = useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
|
|
56
|
-
return [storeSnapshot, service.send, service];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { useMachine, useService };
|
package/fsm/package.json
DELETED