@synapse-sdk/react 0.3.7 → 0.3.9
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 +5 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -6,6 +6,11 @@ React hooks for a Synapse node: `<SynapseProvider node={node}>` above your compo
|
|
|
6
6
|
`useSceneStatus(scene)`, `useTasks(select?)` and `useDiscover()` (your clusters, once signed in). Every hook reads a value the node keeps current; none keeps its own
|
|
7
7
|
copy.
|
|
8
8
|
|
|
9
|
+
`useCatalog().topics` lists every topic that has a publisher or a subscriber that reads it with a schema: each entry
|
|
10
|
+
has the topic's shape (`desc`), its `publishers` and its `subscribers` (`{ name }` per node). A controller waiting for
|
|
11
|
+
commands shows up there before anyone publishes. A subscription by name only, or to a topic defined without a schema,
|
|
12
|
+
is not listed.
|
|
13
|
+
|
|
9
14
|
## Two kinds of users
|
|
10
15
|
|
|
11
16
|
- **Node author** (a robot driver, a sim, a task, a panel that edits a few known things): `node.store(name)` with
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,8 @@ type AuthState = {
|
|
|
16
16
|
* Makes `node` the node of every hook below. With `useAuth` (Clerk's own `useAuth`, or `fakeAuth(token)`), the person
|
|
17
17
|
* signed in there is the node's (`node.setAuth`): signed in → the node asks the key server with their credential;
|
|
18
18
|
* signed out → `node.setAuth(undefined)`; not known yet → nothing; a different `userId` while signed in → a new sign-in. `useAuth` is a hook: pass it on every render or never.
|
|
19
|
-
* Signing out ends no live session.
|
|
19
|
+
* Signing out ends no live session. The sign-in is set in a layout effect, so a child's effect on first mount (a
|
|
20
|
+
* `connect("<runtime>@<cluster>")`) finds it on the node.
|
|
20
21
|
*/
|
|
21
22
|
export declare function SynapseProvider({ node, useAuth, children }: {
|
|
22
23
|
node: Synapse;
|
package/dist/index.js
CHANGED
|
@@ -3,22 +3,25 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Statuses speak TanStack here (`idle | pending | success | error`, like `useMutation`); the spec's
|
|
5
5
|
// five-state `RunStatus` stays on the `Run` the hooks hand back. One rule, two layers.
|
|
6
|
-
import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
|
+
import { createContext, createElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
7
7
|
import { replaceEqualDeep, shallowEqual } from "@synapse-sdk/client";
|
|
8
8
|
import { toSynapseError } from "@synapse-sdk/core";
|
|
9
9
|
const SynapseContext = createContext(null);
|
|
10
|
+
/** `useLayoutEffect` in the browser, `useEffect` on the server (where React 18 warns on a layout effect). */
|
|
11
|
+
const useLayoutEffectSafe = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
10
12
|
/**
|
|
11
13
|
* Makes `node` the node of every hook below. With `useAuth` (Clerk's own `useAuth`, or `fakeAuth(token)`), the person
|
|
12
14
|
* signed in there is the node's (`node.setAuth`): signed in → the node asks the key server with their credential;
|
|
13
15
|
* signed out → `node.setAuth(undefined)`; not known yet → nothing; a different `userId` while signed in → a new sign-in. `useAuth` is a hook: pass it on every render or never.
|
|
14
|
-
* Signing out ends no live session.
|
|
16
|
+
* Signing out ends no live session. The sign-in is set in a layout effect, so a child's effect on first mount (a
|
|
17
|
+
* `connect("<runtime>@<cluster>")`) finds it on the node.
|
|
15
18
|
*/
|
|
16
19
|
export function SynapseProvider({ node, useAuth, children }) {
|
|
17
20
|
const auth = useAuth?.();
|
|
18
21
|
const getToken = useRef(auth?.getToken);
|
|
19
22
|
getToken.current = auth?.getToken;
|
|
20
23
|
const loaded = auth?.isLoaded, signedIn = auth?.isSignedIn, userId = auth?.userId ?? undefined;
|
|
21
|
-
|
|
24
|
+
useLayoutEffectSafe(() => {
|
|
22
25
|
if (!loaded)
|
|
23
26
|
return;
|
|
24
27
|
if (signedIn)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synapse-sdk/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "Synapse SDK React hooks: connection, topics, calls, services, store.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@synapse-sdk/core": "0.3.
|
|
18
|
-
"@synapse-sdk/client": "0.3.
|
|
17
|
+
"@synapse-sdk/core": "0.3.9",
|
|
18
|
+
"@synapse-sdk/client": "0.3.9"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": ">=18"
|