@the-link/react 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,4 +1,68 @@
1
- # React
1
+ # The Link React
2
2
 
3
- React bindings for The Link.
3
+ React bindings for Core tunnels and synchronized properties. The package keeps
4
+ the underlying Link objects authoritative and uses React only to subscribe and
5
+ render their current values.
4
6
 
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @the-link/react @the-link/core react
11
+ ```
12
+
13
+ ## Tunnel events
14
+
15
+ `ReactTunnel.useFactory()` keeps one wrapper for a tunnel reference. Its hooks
16
+ subscribe with React lifecycle cleanup.
17
+
18
+ ```tsx
19
+ import { ReactTunnel } from "@the-link/react"
20
+ import type { Tunnel } from "@the-link/core"
21
+
22
+ export function Status({ tunnel }: { tunnel: Tunnel }) {
23
+ const events = ReactTunnel.useFactory(tunnel)
24
+ const status = events.useFirstState("status:changed", "idle")
25
+
26
+ return <span>{status}</span>
27
+ }
28
+ ```
29
+
30
+ Use `useState(event, initialTuple)` when every event value is needed, or
31
+ `useSubscribe(event, handler)` for an effect-style subscription. As with React
32
+ hooks generally, call these methods unconditionally while rendering a component.
33
+
34
+ ## Properties
35
+
36
+ `useProperty()` reads a Core `Property` through `useSyncExternalStore`. The
37
+ property remains the source of truth; React does not maintain a second copy.
38
+
39
+ ```tsx
40
+ import { useProperty } from "@the-link/react"
41
+ import type { Property } from "@the-link/core"
42
+
43
+ export function Theme({ property }: { property: Property<string> }) {
44
+ const theme = useProperty(property)
45
+
46
+ return <span>{theme}</span>
47
+ }
48
+ ```
49
+
50
+ ## Entry points
51
+
52
+ | Import | Contract |
53
+ | --- | --- |
54
+ | `@the-link/react` | `ReactTunnel` and `useProperty()` |
55
+
56
+ React and `@the-link/core` are peer dependencies, so the application owns their
57
+ instances.
58
+
59
+ ## Development
60
+
61
+ ```sh
62
+ bun install --frozen-lockfile
63
+ bun run verify
64
+ ```
65
+
66
+ ## License
67
+
68
+ MIT
@@ -1,4 +1,4 @@
1
- import Property from "@the-link/core/property";
1
+ import { Property } from "@the-link/core";
2
2
  /**
3
3
  * React hook for reading a Property value reactively.
4
4
  *
@@ -18,4 +18,4 @@ import Property from "@the-link/core/property";
18
18
  * }
19
19
  * ```
20
20
  */
21
- export default function useProperty<Value>(property: Property<Value>): Value;
21
+ export declare function useProperty<Value>(property: Property<Value>): Value;
@@ -18,7 +18,7 @@ import { useCallback, useSyncExternalStore } from "react";
18
18
  * }
19
19
  * ```
20
20
  */
21
- export default function useProperty(property) {
21
+ export function useProperty(property) {
22
22
  const subscribe = useCallback((changed) => property.tunnel.subscribe("change", changed), [property]);
23
23
  const snapshot = useCallback(() => property.value, [property]);
24
24
  return useSyncExternalStore(subscribe, snapshot, snapshot);
@@ -1,4 +1,4 @@
1
- import Tunnel, { Subscriber } from "@the-link/core/tunnel";
1
+ import { Tunnel, type Subscriber } from "@the-link/core";
2
2
  /**
3
3
  * React hook helper for a Tunnel instance.
4
4
  *
@@ -16,7 +16,7 @@ import Tunnel, { Subscriber } from "@the-link/core/tunnel";
16
16
  * }
17
17
  * ```
18
18
  */
19
- export default class ReactTunnel {
19
+ export declare class ReactTunnel {
20
20
  /**
21
21
  * Tunnel instance used by the React hook helpers.
22
22
  */
@@ -16,7 +16,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
16
16
  * }
17
17
  * ```
18
18
  */
19
- export default class ReactTunnel {
19
+ export class ReactTunnel {
20
20
  /**
21
21
  * Tunnel instance used by the React hook helpers.
22
22
  */
@@ -0,0 +1,2 @@
1
+ export { ReactTunnel } from "./react-tunnel.js";
2
+ export { useProperty } from "./property-hook.js";
package/dist/react.js ADDED
@@ -0,0 +1,2 @@
1
+ export { ReactTunnel } from "./react-tunnel.js";
2
+ export { useProperty } from "./property-hook.js";
package/package.json CHANGED
@@ -1,19 +1,15 @@
1
1
  {
2
2
  "name": "@the-link/react",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "React bindings for The Link.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
- "main": "dist/react-tunnel.js",
8
- "types": "dist/react-tunnel.d.ts",
7
+ "main": "dist/react.js",
8
+ "types": "dist/react.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/react-tunnel.d.ts",
12
- "default": "./dist/react-tunnel.js"
13
- },
14
- "./property": {
15
- "types": "./dist/property-hook.d.ts",
16
- "default": "./dist/property-hook.js"
11
+ "types": "./dist/react.d.ts",
12
+ "default": "./dist/react.js"
17
13
  }
18
14
  },
19
15
  "files": ["dist", "LICENSE", "README.md"],
@@ -38,11 +34,11 @@
38
34
  "prepack": "node --run build"
39
35
  },
40
36
  "peerDependencies": {
41
- "@the-link/core": "^0.1.0",
37
+ "@the-link/core": "^0.2.0",
42
38
  "react": "^19.2.0"
43
39
  },
44
40
  "devDependencies": {
45
- "@the-link/core": "^0.1.0",
41
+ "@the-link/core": "^0.2.0",
46
42
  "@types/react": "^19.2.18",
47
43
  "react": "^19.2.8",
48
44
  "typescript": "^6.0.3"