@xstate/react 7.0.0-alpha.2 → 7.0.0-alpha.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/README.md
CHANGED
|
@@ -44,3 +44,9 @@ export const Toggler = () => {
|
|
|
44
44
|
);
|
|
45
45
|
};
|
|
46
46
|
```
|
|
47
|
+
|
|
48
|
+
## Observing an actor
|
|
49
|
+
|
|
50
|
+
<!-- observer lifecycle from src/useActorRef.ts -->
|
|
51
|
+
|
|
52
|
+
Pass a snapshot listener or observer as the third argument to `useActorRef(logic, options, observer)`. It subscribes before the actor starts. When changing the machine configuration replaces the actor, the observer follows the replacement, even when the callback identity stays the same. Unmounting unsubscribes the observer and stops the actor.
|
package/dist/xstate-react.cjs.js
CHANGED
|
@@ -65,7 +65,6 @@ function useActorLifecycle(actorRef, setActorRef, createReplacement) {
|
|
|
65
65
|
// actor. A stopped actor cannot be restarted.
|
|
66
66
|
if (actorRef._processingStatus === 2 /* ProcessingStatus.Stopped */ && actorRef.getSnapshot()?.status === 'stopped') {
|
|
67
67
|
const newActor = createReplacement();
|
|
68
|
-
newActor.start();
|
|
69
68
|
setActorRef(newActor);
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
@@ -97,7 +96,7 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
97
96
|
return () => {
|
|
98
97
|
sub.unsubscribe();
|
|
99
98
|
};
|
|
100
|
-
}, [observerOrListener]);
|
|
99
|
+
}, [actorRef, observerOrListener]);
|
|
101
100
|
useActorLifecycle(actorRef, setActorRef, () => xstate.createActor(machine, actorRef.options));
|
|
102
101
|
return actorRef;
|
|
103
102
|
}
|
|
@@ -65,7 +65,6 @@ function useActorLifecycle(actorRef, setActorRef, createReplacement) {
|
|
|
65
65
|
// actor. A stopped actor cannot be restarted.
|
|
66
66
|
if (actorRef._processingStatus === 2 /* ProcessingStatus.Stopped */ && actorRef.getSnapshot()?.status === 'stopped') {
|
|
67
67
|
const newActor = createReplacement();
|
|
68
|
-
newActor.start();
|
|
69
68
|
setActorRef(newActor);
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
@@ -97,7 +96,7 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
97
96
|
return () => {
|
|
98
97
|
sub.unsubscribe();
|
|
99
98
|
};
|
|
100
|
-
}, [observerOrListener]);
|
|
99
|
+
}, [actorRef, observerOrListener]);
|
|
101
100
|
useActorLifecycle(actorRef, setActorRef, () => xstate.createActor(machine, actorRef.options));
|
|
102
101
|
return actorRef;
|
|
103
102
|
}
|
|
@@ -39,7 +39,6 @@ function useActorLifecycle(actorRef, setActorRef, createReplacement) {
|
|
|
39
39
|
// actor. A stopped actor cannot be restarted.
|
|
40
40
|
if (actorRef._processingStatus === 2 /* ProcessingStatus.Stopped */ && actorRef.getSnapshot()?.status === 'stopped') {
|
|
41
41
|
const newActor = createReplacement();
|
|
42
|
-
newActor.start();
|
|
43
42
|
setActorRef(newActor);
|
|
44
43
|
return;
|
|
45
44
|
}
|
|
@@ -71,7 +70,7 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
71
70
|
return () => {
|
|
72
71
|
sub.unsubscribe();
|
|
73
72
|
};
|
|
74
|
-
}, [observerOrListener]);
|
|
73
|
+
}, [actorRef, observerOrListener]);
|
|
75
74
|
useActorLifecycle(actorRef, setActorRef, () => createActor(machine, actorRef.options));
|
|
76
75
|
return actorRef;
|
|
77
76
|
}
|
package/dist/xstate-react.esm.js
CHANGED
|
@@ -39,7 +39,6 @@ function useActorLifecycle(actorRef, setActorRef, createReplacement) {
|
|
|
39
39
|
// actor. A stopped actor cannot be restarted.
|
|
40
40
|
if (actorRef._processingStatus === 2 /* ProcessingStatus.Stopped */ && actorRef.getSnapshot()?.status === 'stopped') {
|
|
41
41
|
const newActor = createReplacement();
|
|
42
|
-
newActor.start();
|
|
43
42
|
setActorRef(newActor);
|
|
44
43
|
return;
|
|
45
44
|
}
|
|
@@ -71,7 +70,7 @@ function useActorRef(machine, ...[options, observerOrListener]) {
|
|
|
71
70
|
return () => {
|
|
72
71
|
sub.unsubscribe();
|
|
73
72
|
};
|
|
74
|
-
}, [observerOrListener]);
|
|
73
|
+
}, [actorRef, observerOrListener]);
|
|
75
74
|
useActorLifecycle(actorRef, setActorRef, () => createActor(machine, actorRef.options));
|
|
76
75
|
return actorRef;
|
|
77
76
|
}
|
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.3",
|
|
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.59"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"xstate": {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"react-dom": "^19.0.0",
|
|
75
75
|
"rxjs": "^7.8.1",
|
|
76
76
|
"zod": "^3.25.51",
|
|
77
|
-
"xstate": "^6.0.0-alpha.
|
|
77
|
+
"xstate": "^6.0.0-alpha.59"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {}
|
|
80
80
|
}
|