@typeonce/effect-machine-react 0.28.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sandro Maglione
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,3 @@
1
+ Portions are adapted from the Effect project, which is distributed under the
2
+ MIT License. See https://github.com/Effect-TS/effect and the source history for
3
+ authorship and provenance.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @typeonce/effect-machine-react
2
+
3
+ React ownership hooks for machine atoms created by
4
+ [`@typeonce/effect-machine`](../effect-machine/README.md).
5
+
6
+ ```tsx
7
+ import { useMachineAtom } from "@typeonce/effect-machine-react"
8
+
9
+ function AuthProvider({ input, children }: Props) {
10
+ const machine = useMachineAtom(() => MachineAtoms.make(AuthMachine, input))
11
+
12
+ return (
13
+ <AuthContext.Provider value={machine}>
14
+ {children}
15
+ </AuthContext.Provider>
16
+ )
17
+ }
18
+ ```
19
+
20
+ `useMachineAtom` strongly owns one machine atom, mounts it after commit, and
21
+ does not subscribe the owner to machine state. Descendants subscribe to the
22
+ specific state paths they render with `AtomMachine.select`,
23
+ `AtomMachine.selectSnapshot`, or `AtomMachine.matches`.
24
+
25
+ Machine input is startup-only. Send an event to update a running workflow, or
26
+ change the provider's React `key` to replace it with a new machine.
@@ -0,0 +1,16 @@
1
+ import type { AtomMachine } from "@typeonce/effect-machine/reactivity";
2
+ type AnyMachineAtom = AtomMachine.MachineAtom<any, never, any, any, any, any>;
3
+ /**
4
+ * Creates one machine atom for a committed React owner and mounts its machine
5
+ * reference without subscribing the owner to machine state.
6
+ *
7
+ * The factory is startup-only. Later changes to values captured by the factory
8
+ * do not replace the machine. Send an event to change a running workflow, or
9
+ * change the owner's React `key` to create a new machine.
10
+ *
11
+ * @category hooks
12
+ * @since 0.29.0
13
+ */
14
+ export declare const useMachineAtom: <A extends AnyMachineAtom>(create: () => A) => A;
15
+ export {};
16
+ //# sourceMappingURL=MachineAtom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MachineAtom.d.ts","sourceRoot":"","sources":["../src/MachineAtom.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAA;AAGtE,KAAK,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAE7E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,cAAc,EAAE,QAAQ,MAAM,CAAC,KAAG,CAI1E,CAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * React ownership for machine atoms.
3
+ *
4
+ * @since 0.29.0
5
+ */
6
+ "use client";
7
+ import { useAtomMount } from "@effect/atom-react";
8
+ import * as React from "react";
9
+ /**
10
+ * Creates one machine atom for a committed React owner and mounts its machine
11
+ * reference without subscribing the owner to machine state.
12
+ *
13
+ * The factory is startup-only. Later changes to values captured by the factory
14
+ * do not replace the machine. Send an event to change a running workflow, or
15
+ * change the owner's React `key` to create a new machine.
16
+ *
17
+ * @category hooks
18
+ * @since 0.29.0
19
+ */
20
+ export const useMachineAtom = (create) => {
21
+ const [machine] = React.useState(create);
22
+ useAtomMount(machine.ref);
23
+ return machine;
24
+ };
25
+ //# sourceMappingURL=MachineAtom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MachineAtom.js","sourceRoot":"","sources":["../src/MachineAtom.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,CAAA;AAEZ,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAA2B,MAAe,EAAK,EAAE;IAC7E,MAAM,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACzB,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * React ownership hooks for Effect Machine atoms.
3
+ *
4
+ * @since 0.29.0
5
+ */
6
+ export * from "./MachineAtom.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * React ownership hooks for Effect Machine atoms.
3
+ *
4
+ * @since 0.29.0
5
+ */
6
+ export * from "./MachineAtom.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,kBAAkB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@typeonce/effect-machine-react",
3
+ "version": "0.28.0",
4
+ "description": "React ownership hooks for Effect Machine atoms",
5
+ "author": "Sandro Maglione",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/typeonce-dev/effect-machine.git",
9
+ "directory": "packages/effect-machine-react"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/typeonce-dev/effect-machine/issues"
13
+ },
14
+ "homepage": "https://github.com/typeonce-dev/effect-machine/tree/main/packages/effect-machine-react#readme",
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "src/**/*.ts",
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE",
23
+ "NOTICE"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "provenance": true
35
+ },
36
+ "dependencies": {
37
+ "@typeonce/effect-machine": "^0.28.0"
38
+ },
39
+ "peerDependencies": {
40
+ "@effect/atom-react": "4.0.0-rc.112",
41
+ "effect": "4.0.0-rc.112",
42
+ "react": ">=19.0.0 <20.0.0",
43
+ "scheduler": ">=0.25.0 <0.28.0"
44
+ },
45
+ "devDependencies": {
46
+ "@effect/atom-react": "4.0.0-rc.112",
47
+ "@testing-library/react": "16.3.0",
48
+ "@types/react": "19.2.16",
49
+ "@types/react-dom": "19.2.3",
50
+ "effect": "4.0.0-rc.112",
51
+ "jsdom": "27.2.0",
52
+ "react": "19.2.7",
53
+ "react-dom": "19.2.7",
54
+ "scheduler": "0.27.0",
55
+ "tstyche": "7.2.1",
56
+ "typescript": "6.0.3",
57
+ "vitest": "4.1.10"
58
+ },
59
+ "engines": {
60
+ "node": ">=20"
61
+ },
62
+ "scripts": {
63
+ "build": "tsc -b tsconfig.build.json",
64
+ "check": "tsc -b tsconfig.json",
65
+ "test:types": "tstyche"
66
+ }
67
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * React ownership for machine atoms.
3
+ *
4
+ * @since 0.29.0
5
+ */
6
+ "use client"
7
+
8
+ import { useAtomMount } from "@effect/atom-react"
9
+ import type { AtomMachine } from "@typeonce/effect-machine/reactivity"
10
+ import * as React from "react"
11
+
12
+ type AnyMachineAtom = AtomMachine.MachineAtom<any, never, any, any, any, any>
13
+
14
+ /**
15
+ * Creates one machine atom for a committed React owner and mounts its machine
16
+ * reference without subscribing the owner to machine state.
17
+ *
18
+ * The factory is startup-only. Later changes to values captured by the factory
19
+ * do not replace the machine. Send an event to change a running workflow, or
20
+ * change the owner's React `key` to create a new machine.
21
+ *
22
+ * @category hooks
23
+ * @since 0.29.0
24
+ */
25
+ export const useMachineAtom = <A extends AnyMachineAtom>(create: () => A): A => {
26
+ const [machine] = React.useState(create)
27
+ useAtomMount(machine.ref)
28
+ return machine
29
+ }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * React ownership hooks for Effect Machine atoms.
3
+ *
4
+ * @since 0.29.0
5
+ */
6
+
7
+ export * from "./MachineAtom.js"