@phreshos/react 0.1.20 → 0.1.21
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.
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Process } from "@phreshos/core";
|
|
2
|
-
/** Mutable lifecycle state of one Process
|
|
2
|
+
/** Mutable lifecycle state of one Process. */
|
|
3
3
|
export type ProcessState = Readonly<{
|
|
4
4
|
exited: boolean;
|
|
5
|
-
serverExists: boolean;
|
|
6
|
-
clientExists: boolean;
|
|
7
5
|
}>;
|
|
8
6
|
/** Explicitly reads and follows one Process while this hook is mounted. */
|
|
9
7
|
export default function useProcessState(process: Process): ProcessState | undefined;
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { useMemo, useSyncExternalStore } from "react";
|
|
2
|
-
import LiveState
|
|
2
|
+
import LiveState from "./live-state.js";
|
|
3
3
|
/** Explicitly reads and follows one Process while this hook is mounted. */
|
|
4
4
|
export default function useProcessState(process) {
|
|
5
|
-
const state = useMemo(() => new LiveState(async () => {
|
|
6
|
-
const [exited, serverExists, clientExists] = await Promise.all([
|
|
7
|
-
process.exited(),
|
|
8
|
-
process.server.exists(),
|
|
9
|
-
process.client.exists()
|
|
10
|
-
]);
|
|
11
|
-
return { exited, serverExists, clientExists };
|
|
12
|
-
}, reduce => combineCleanups(process.server.lifecycle.subscribe("start", () => reduce(current => current.serverExists ? current : { ...current, serverExists: true })), process.server.lifecycle.subscribe("stop", () => reduce(current => current.serverExists ? { ...current, serverExists: false } : current)), process.client.lifecycle.subscribe("start", () => reduce(current => current.clientExists ? current : { ...current, clientExists: true })), process.client.lifecycle.subscribe("stop", () => reduce(current => current.clientExists ? { ...current, clientExists: false } : current)), process.subscribe("exit", () => reduce(current => ({ ...current, exited: true, serverExists: false, clientExists: false }))))), [process]);
|
|
5
|
+
const state = useMemo(() => new LiveState(async () => ({ exited: await process.exited() }), reduce => process.subscribe("exit", () => reduce(current => current.exited ? current : { exited: true }))), [process]);
|
|
13
6
|
return useSyncExternalStore(state.subscribe, state.snapshot, state.snapshot);
|
|
14
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Runtime-neutral React adapters for PhreshOS contracts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -47,11 +47,12 @@
|
|
|
47
47
|
"prepack": "node --run test && node --run build"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@phreshos/core": "^0.1.
|
|
50
|
+
"@phreshos/core": "^0.1.42",
|
|
51
51
|
"react": "^19.2.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@phreshos/core": "^0.1.
|
|
54
|
+
"@phreshos/core": "^0.1.42",
|
|
55
|
+
"@testing-library/dom": "^10.4.1",
|
|
55
56
|
"@testing-library/react": "^16.3.0",
|
|
56
57
|
"@types/react": "^19.2.18",
|
|
57
58
|
"@types/react-dom": "^19.2.4",
|