8 |
{JSON.stringify(snapshot.value, null, 2)}
9 |
15 | send({ type: "time", params: { updatedTime: audioRef.currentTime } })
16 | }
17 | onError={({ type }) =>
18 | send({ type: "init-error", params: { message: type } })
19 | }
20 | onLoadedData={({ currentTarget: audioRef }) =>
21 | send({ type: "loading", params: { audioRef } })
22 | }
23 | onEnded={() => send({ type: "end" })}
24 | />
25 |
26 | {`Current time: ${snapshot.context.currentTime}`}
27 |
28 |
29 | {snapshot.matches({ Active: "Paused" }) && (
30 | send({ type: "play" })}>Play
31 | )}
32 |
33 | {snapshot.matches({ Active: "Playing" }) && (
34 | send({ type: "pause" })}>Pause
35 | )}
36 |
37 | {snapshot.matches("Active") && (
38 | send({ type: "restart" })}>Restart
39 | )}
40 |
41 |
42 | );
43 | }
44 |
--------------------------------------------------------------------------------
/first-example/pnpm-lock.yaml:
--------------------------------------------------------------------------------
1 | lockfileVersion: '6.0'
2 |
3 | settings:
4 | autoInstallPeers: true
5 | excludeLinksFromLockfile: false
6 |
7 | dependencies:
8 | '@effect/schema':
9 | specifier: ^0.53.3
10 | version: 0.53.3(effect@2.0.0-next.60)(fast-check@3.14.0)
11 | effect:
12 | specifier: 2.0.0-next.60
13 | version: 2.0.0-next.60
14 | xstate:
15 | specifier: ^5.3.0
16 | version: 5.3.0
17 |
18 | devDependencies:
19 | typescript:
20 | specifier: ^5.3.3
21 | version: 5.3.3
22 |
23 | packages:
24 |
25 | /@effect/schema@0.53.3(effect@2.0.0-next.60)(fast-check@3.14.0):
26 | resolution: {integrity: sha512-QycmIqn2E7v0IPzHqSXmdnX7fhgr102z90BAjBUsifJy5MOfC9EdxTJ5DY8Vxiq9gjbLz7QWBQuCyqRDJ6eNAQ==}
27 | peerDependencies:
28 | effect: 2.0.0-next.60
29 | fast-check: ^3.13.2
30 | dependencies:
31 | effect: 2.0.0-next.60
32 | fast-check: 3.14.0
33 | dev: false
34 |
35 | /effect@2.0.0-next.60:
36 | resolution: {integrity: sha512-23KhlVACgrg5UPFu9i4szybSU4cCU4T/7CX4pe0jV84QBZX0zm96WzwCtg6dqOnmUzBL7hm6S+iiPW2Rab13Uw==}
37 | dev: false
38 |
39 | /fast-check@3.14.0:
40 | resolution: {integrity: sha512-9Z0zqASzDNjXBox/ileV/fd+4P+V/f3o4shM6QawvcdLFh8yjPG4h5BrHUZ8yzY6amKGDTAmRMyb/JZqe+dCgw==}
41 | engines: {node: '>=8.0.0'}
42 | dependencies:
43 | pure-rand: 6.0.4
44 | dev: false
45 |
46 | /pure-rand@6.0.4:
47 | resolution: {integrity: sha512-LA0Y9kxMYv47GIPJy6MI84fqTd2HmYZI83W/kM/SkKfDlajnZYfmXFTxkbY+xSBPkLJxltMa9hIkmdc29eguMA==}
48 | dev: false
49 |
50 | /typescript@5.3.3:
51 | resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==}
52 | engines: {node: '>=14.17'}
53 | hasBin: true
54 | dev: true
55 |
56 | /xstate@5.3.0:
57 | resolution: {integrity: sha512-7Fx5TgxAFA1vhjtYp46U3+6XbCIZNobBJpT3MdeRb4msOioyKP1YJte9R8GMXh7ilFrGuHx72E836/7KYVkK1w==}
58 | dev: false
59 |
--------------------------------------------------------------------------------
/actor-emit-events/src/App.tsx:
--------------------------------------------------------------------------------
1 | import { useMachine, useSelector } from "@xstate/react";
2 | import { useEffect } from "react";
3 | import type { ActorRefFrom } from "xstate";
4 | import {
5 | rootMachine,
6 | type notifierMachine,
7 | type uploadMachine,
8 | } from "./machine";
9 |
10 | export default function App() {
11 | const [snapshot] = useMachine(rootMachine);
12 | const notifierActor = snapshot.children["notifier"];
13 |
14 | /// 🔥 Root machine can react to events triggered by child machine
15 | useEffect(() => {
16 | /// 👇 Access emitted event from `child`
17 | const { unsubscribe } = snapshot.context.child.on(
18 | "uploaded",
19 | ({ value }) => {
20 | console.log("Uploaded value", { value });
21 | }
22 | );
23 |
24 | return unsubscribe;
25 | }, []);
26 |
27 | return (
28 | <>
29 | {notifierActor &&