@phreshos/react 0.1.28 → 0.1.29
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,6 +1,6 @@
|
|
|
1
1
|
import type { Endpoint } from "@phreshos/core";
|
|
2
2
|
export type EndpointState = Readonly<{
|
|
3
|
-
|
|
3
|
+
running: boolean;
|
|
4
4
|
}>;
|
|
5
5
|
/** Explicitly reads and follows one Endpoint address while mounted. */
|
|
6
6
|
export default function useEndpointState(endpoint: Endpoint): EndpointState | undefined;
|
|
@@ -2,9 +2,9 @@ import { useMemo, useSyncExternalStore } from "react";
|
|
|
2
2
|
import LiveState, { combineCleanups } from "./live-state.js";
|
|
3
3
|
/** Explicitly reads and follows one Endpoint address while mounted. */
|
|
4
4
|
export default function useEndpointState(endpoint) {
|
|
5
|
-
const state = useMemo(() => new LiveState(async () => ({
|
|
5
|
+
const state = useMemo(() => new LiveState(async () => ({ running: await endpoint.running() }), reduce => combineCleanups(endpoint.lifecycle.subscribe("start", () => reduce(current => setRunning(current, true))), endpoint.lifecycle.subscribe("stop", () => reduce(current => setRunning(current, false))))), [endpoint]);
|
|
6
6
|
return useSyncExternalStore(state.subscribe, state.snapshot, state.snapshot);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
return state.
|
|
8
|
+
function setRunning(state, running) {
|
|
9
|
+
return state.running === running ? state : { running };
|
|
10
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Service } from "@phreshos/core";
|
|
2
|
-
/** Live
|
|
2
|
+
/** Live availability of one stable Service address. */
|
|
3
3
|
export type ServiceState = Readonly<{
|
|
4
|
-
|
|
4
|
+
available: boolean;
|
|
5
5
|
}>;
|
|
6
6
|
/** Explicitly reads and follows one service while this hook is mounted. */
|
|
7
7
|
export default function useServiceState(service: Service): ServiceState | undefined;
|
|
@@ -2,9 +2,9 @@ import { useMemo, useSyncExternalStore } from "react";
|
|
|
2
2
|
import LiveState, { combineCleanups } from "./live-state.js";
|
|
3
3
|
/** Explicitly reads and follows one service while this hook is mounted. */
|
|
4
4
|
export default function useServiceState(service) {
|
|
5
|
-
const state = useMemo(() => new LiveState(async () => ({
|
|
5
|
+
const state = useMemo(() => new LiveState(async () => ({ available: await service.available() }), reduce => combineCleanups(service.lifecycle.subscribe("available", () => reduce(current => setAvailable(current, true))), service.lifecycle.subscribe("unavailable", () => reduce(current => setAvailable(current, false))))), [service]);
|
|
6
6
|
return useSyncExternalStore(state.subscribe, state.snapshot, state.snapshot);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
return state.
|
|
8
|
+
function setAvailable(state, available) {
|
|
9
|
+
return state.available === available ? state : { available };
|
|
10
10
|
}
|
package/dist/use-window-state.js
CHANGED
|
@@ -3,9 +3,11 @@ import LiveState, { combineCleanups } from "./live-state.js";
|
|
|
3
3
|
/** Explicitly reads and follows one live Client Window while mounted. */
|
|
4
4
|
export default function useWindowState(window) {
|
|
5
5
|
const state = useMemo(() => new LiveState(async () => {
|
|
6
|
-
const [title, header, position, size, minimized, maximized, front, layer] = await Promise.all([
|
|
6
|
+
const [title, header, frame, transaction, position, size, minimized, maximized, front, layer] = await Promise.all([
|
|
7
7
|
window.title(),
|
|
8
8
|
window.header(),
|
|
9
|
+
window.frame(),
|
|
10
|
+
window.transaction(),
|
|
9
11
|
window.position(),
|
|
10
12
|
window.size(),
|
|
11
13
|
window.minimized(),
|
|
@@ -13,7 +15,7 @@ export default function useWindowState(window) {
|
|
|
13
15
|
window.front(),
|
|
14
16
|
window.layer()
|
|
15
17
|
]);
|
|
16
|
-
return { title, header, position, size, minimized, maximized, front, layer };
|
|
17
|
-
}, reduce => combineCleanups(window.subscribe("move", position => reduce(current => ({ ...current, position }))), window.subscribe("resize", size => reduce(current => ({ ...current, size }))), window.subscribe("minimize", minimized => reduce(current => ({ ...current, minimized }))), window.subscribe("maximize", maximized => reduce(current => ({ ...current, maximized }))), window.subscribe("changeTitle", title => reduce(current => ({ ...current, title }))), window.subscribe("changeHeader", header => reduce(current => ({ ...current, header }))), window.subscribe("front", front => reduce(current => ({ ...current, front }))))), [window]);
|
|
18
|
+
return { title, header, frame, transaction, position, size, minimized, maximized, front, layer };
|
|
19
|
+
}, reduce => combineCleanups(window.subscribe("move", position => reduce(current => ({ ...current, position }))), window.subscribe("resize", size => reduce(current => ({ ...current, size }))), window.subscribe("minimize", minimized => reduce(current => ({ ...current, minimized }))), window.subscribe("maximize", maximized => reduce(current => ({ ...current, maximized }))), window.subscribe("changeTitle", title => reduce(current => ({ ...current, title }))), window.subscribe("changeHeader", header => reduce(current => ({ ...current, header }))), window.subscribe("changeFrame", frame => reduce(current => ({ ...current, frame }))), window.subscribe("changeTransaction", transaction => reduce(current => ({ ...current, transaction }))), window.subscribe("front", front => reduce(current => ({ ...current, front }))))), [window]);
|
|
18
20
|
return useSyncExternalStore(state.subscribe, state.snapshot, state.snapshot);
|
|
19
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Runtime-neutral React adapters for PhreshOS contracts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"prepack": "node --run build"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@phreshos/core": "^0.1.
|
|
49
|
+
"@phreshos/core": "^0.1.55",
|
|
50
50
|
"react": "^19.2.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@phreshos/core": "^0.1.
|
|
53
|
+
"@phreshos/core": "^0.1.55",
|
|
54
54
|
"@testing-library/dom": "^10.4.1",
|
|
55
55
|
"@testing-library/react": "^16.3.0",
|
|
56
56
|
"@types/react": "^19.2.18",
|