@phreshos/react 0.1.15 → 0.1.16
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 +1 -1
- package/dist/use-service-state.d.ts +2 -2
- package/dist/use-service-state.js +3 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Service } from "@phreshos/client";
|
|
2
|
-
/** Live
|
|
2
|
+
/** Live existence of one configured Endpoint service. */
|
|
3
3
|
export type ServiceState = Readonly<{
|
|
4
|
-
|
|
4
|
+
exists: 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 () => ({ exists: await service.exists() }), reduce => combineCleanups(service.lifecycle.subscribe("start", () => reduce(current => setExists(current, true))), service.lifecycle.subscribe("stop", () => reduce(current => setExists(current, false))))), [service]);
|
|
6
6
|
return useSyncExternalStore(state.subscribe, state.snapshot, state.snapshot);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
return state.
|
|
8
|
+
function setExists(state, exists) {
|
|
9
|
+
return state.exists === exists ? state : { exists };
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "React adapters for the Client SDK.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"prepack": "node --run test && node --run build"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@phreshos/client": "^0.1.
|
|
51
|
-
"@phreshos/core": "^0.1.
|
|
50
|
+
"@phreshos/client": "^0.1.28",
|
|
51
|
+
"@phreshos/core": "^0.1.29",
|
|
52
52
|
"react": "^19.2.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@phreshos/client": "^0.1.
|
|
56
|
-
"@phreshos/core": "^0.1.
|
|
55
|
+
"@phreshos/client": "^0.1.28",
|
|
56
|
+
"@phreshos/core": "^0.1.29",
|
|
57
57
|
"@testing-library/react": "^16.3.0",
|
|
58
58
|
"@types/react": "^19.2.18",
|
|
59
59
|
"@types/react-dom": "^19.2.4",
|