@tilia/react 5.2.0 → 6.0.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,6 +1,6 @@
1
1
  # React hooks for tilia
2
2
 
3
- Check the [**website**](https://tiliajs.com) for documentation and examples.
3
+ Check the [documentation](https://tiliajs.dev/react) for the React API and examples.
4
4
 
5
5
  ## API (in case the website is not available)
6
6
 
@@ -30,10 +30,10 @@ let make: tilia => tilia_react
30
30
 
31
31
  ```ts
32
32
  import type { Tilia } from "tilia";
33
- export interface TiliaReact {
33
+ export type TiliaReact = {
34
34
  useTilia: () => void;
35
35
  useComputed: <T>(fn: () => T) => signal<A>;
36
- }
36
+ };
37
37
 
38
38
  export function useTilia(): void;
39
39
  export function useComputed<T>(fn: () => T): signal<T>;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import type { Tilia } from "tilia";
2
- export interface TiliaReact {
2
+ export type TiliaReact = {
3
3
  /** Call at the top of a React component to enable reactive tracking. Prefer `leaf` instead. */
4
4
  useTilia: () => void;
5
5
  /** Compute a value and only re-render when the result changes, not the dependencies. */
6
6
  useComputed: <T>(fn: () => T) => T;
7
7
  /** Wrap a React component for exact dependency tracking (preferred over `useTilia`). */
8
8
  leaf: <T, U>(fn: (p: T) => U) => (p: T) => U;
9
- }
9
+ };
10
10
 
11
11
  /** Create a `@tilia/react` API from a tilia context. */
12
12
  export function make(tilia: Tilia): TiliaReact;
package/llms.txt ADDED
@@ -0,0 +1,75 @@
1
+ # @tilia/react
2
+
3
+ > View adapter for tilia: React components observe reactive objects by
4
+ > reading them during render. Five entries, no store, no selectors.
5
+
6
+ ## Exact API contracts
7
+
8
+ These files are authoritative. If prose differs, follow the contracts.
9
+
10
+ Repository:
11
+
12
+ - TypeScript: `./src/index.d.ts`
13
+ - ReScript: `./src/TiliaReact.resi`
14
+
15
+ Installed npm package:
16
+
17
+ - TypeScript: `./dist/index.d.ts`
18
+ - ReScript: `./src/TiliaReact.resi`
19
+
20
+ Published documentation:
21
+
22
+ - Overview: <https://tiliajs.dev/react>
23
+ - API: <https://tiliajs.dev/react/api>
24
+ - TypeScript contract: <https://github.com/tiliajs/tilia/blob/main/react/src/index.d.ts>
25
+ - ReScript contract: <https://github.com/tiliajs/tilia/blob/main/react/src/TiliaReact.resi>
26
+
27
+ ## Key facts
28
+
29
+ - `leaf(fn)` wraps a component and tracks the reads of its render exactly. It
30
+ is the preferred integration: the observation closes at the end of the render
31
+ function.
32
+ - `useTilia()` tracks the reads of the current render from the call site. It is
33
+ the retrofit for existing components; its boundary is coarser than `leaf`'s
34
+ because a hook cannot see the end of the render.
35
+ - `useComputed(fn)` evaluates `fn` under tracking and re-renders only when the
36
+ returned value changes, not when its dependencies do. Use it for a
37
+ conclusion (`selected`, `due`) instead of the values behind it.
38
+ - `make(tilia)` returns a `TiliaReact`/`tilia_react` record — `useTilia`,
39
+ `useComputed`, `leaf` — bound to one core context. The package-level exports
40
+ are the default-context version.
41
+ - Dependencies are the reads themselves: no dependency arrays, no selectors, no
42
+ `memo` wrapper. Read the feature from a React context and the fields where
43
+ they are used, so the tracking stays fine-grained.
44
+ - React Native needs nothing extra: the adapter observes tilia objects and is
45
+ indifferent to what renders them.
46
+
47
+ ## Minimal TypeScript
48
+
49
+ ```typescript
50
+ import { leaf, useComputed } from "@tilia/react";
51
+
52
+ const CardView = leaf(({ card }: { card: Card }) => {
53
+ const current = useComputed(() => app.deck.queue[0]?.id === card.id);
54
+ return <div className={current ? "current" : ""}>{card.front}</div>;
55
+ });
56
+ ```
57
+
58
+ ## Minimal ReScript
59
+
60
+ ```rescript
61
+ open TiliaReact
62
+
63
+ @react.component
64
+ let make = leaf((~card) => {
65
+ let current = useComputed(() =>
66
+ app.deck.queue[0]->Option.map(c => c.id)->Option.getOr("") === card.id
67
+ )
68
+ <div className={current ? "current" : ""}> {card.front->React.string} </div>
69
+ })
70
+ ```
71
+
72
+ ## Docs
73
+
74
+ - [README](README.md): the API surface in both languages, with examples
75
+ - [tilia machine guide](../tilia/llms.txt): the reactive core this observes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tilia/react",
3
- "version": "5.2.0",
4
- "homepage": "https://tiliajs.com",
3
+ "version": "6.0.0",
4
+ "homepage": "https://tiliajs.dev/react",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
@@ -30,6 +30,6 @@
30
30
  "react": "*"
31
31
  },
32
32
  "dependencies": {
33
- "tilia": "^5.2"
33
+ "tilia": "^6.0"
34
34
  }
35
35
  }
package/rescript.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "tilia"
22
22
  ],
23
23
  "dev-dependencies": [
24
- "vitest-bdd"
24
+ "@epure/vitest"
25
25
  ],
26
26
  "jsx": {
27
27
  "version": 4