@the-link/react 0.1.0 → 0.3.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 +66 -2
- package/dist/property-hook.d.ts +2 -2
- package/dist/property-hook.js +1 -1
- package/dist/react-tunnel.d.ts +2 -2
- package/dist/react-tunnel.js +1 -1
- package/dist/react.d.ts +2 -0
- package/dist/react.js +2 -0
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,4 +1,68 @@
|
|
|
1
|
-
# React
|
|
1
|
+
# The Link React
|
|
2
2
|
|
|
3
|
-
React bindings for The
|
|
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
|
package/dist/property-hook.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Property from "@the-link/core
|
|
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
|
|
21
|
+
export declare function useProperty<Value>(property: Property<Value>): Value;
|
package/dist/property-hook.js
CHANGED
|
@@ -18,7 +18,7 @@ import { useCallback, useSyncExternalStore } from "react";
|
|
|
18
18
|
* }
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
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);
|
package/dist/react-tunnel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import 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
|
|
19
|
+
export declare class ReactTunnel {
|
|
20
20
|
/**
|
|
21
21
|
* Tunnel instance used by the React hook helpers.
|
|
22
22
|
*/
|
package/dist/react-tunnel.js
CHANGED
package/dist/react.d.ts
ADDED
package/dist/react.js
ADDED
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-link/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React bindings for The Link.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"main": "dist/react
|
|
8
|
-
"types": "dist/react
|
|
7
|
+
"main": "dist/react.js",
|
|
8
|
+
"types": "dist/react.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./dist/react
|
|
12
|
-
"default": "./dist/react
|
|
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
|
-
"files": [
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
20
|
"author": "Zohayr SLILEH",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"repository": {
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"prepack": "node --run build"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@the-link/core": "^0.
|
|
41
|
+
"@the-link/core": "^0.4.0",
|
|
42
42
|
"react": "^19.2.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@the-link/core": "^0.
|
|
45
|
+
"@the-link/core": "^0.4.0",
|
|
46
46
|
"@types/react": "^19.2.18",
|
|
47
47
|
"react": "^19.2.8",
|
|
48
48
|
"typescript": "^6.0.3"
|