tilia 5.0.0 → 5.0.1
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/llms-rescript.md +270 -0
- package/llms-typescript.md +281 -0
- package/llms.txt +47 -0
- package/package.json +1 -1
package/llms-rescript.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Tilia LLM Guide (ReScript)
|
|
2
|
+
|
|
3
|
+
AI-focused ReScript documentation for the full Tilia API.
|
|
4
|
+
|
|
5
|
+
## Primary Rule
|
|
6
|
+
|
|
7
|
+
- Use `carve` as the default for feature modules.
|
|
8
|
+
- `carve` must glue parts into one reactive object.
|
|
9
|
+
- Do not put business complexity inside `carve`.
|
|
10
|
+
- Put logic in standalone functions that take `self`.
|
|
11
|
+
- Bind with `field: derived(field)` when possible.
|
|
12
|
+
|
|
13
|
+
## Canonical Carve Pattern
|
|
14
|
+
|
|
15
|
+
```rescript
|
|
16
|
+
open Tilia
|
|
17
|
+
|
|
18
|
+
type feature = {
|
|
19
|
+
mutable count: int,
|
|
20
|
+
double: int,
|
|
21
|
+
add: int => unit,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type service = {
|
|
25
|
+
fetchCount: (int, int => unit) => unit,
|
|
26
|
+
updateCount: (int, unit => unit) => unit,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let double = (self: feature) => self.count * 2
|
|
30
|
+
|
|
31
|
+
let add = (service: service) => (self: feature) => (count: int) => {
|
|
32
|
+
let prevValue = self.count
|
|
33
|
+
self.count += count // optimistic write
|
|
34
|
+
service.updateCount(self.count, () => self.count = prevValue)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let makeFeature = service =>
|
|
38
|
+
carve(({derived}) => {
|
|
39
|
+
count: source(0, service.fetchCount),
|
|
40
|
+
double: derived(double),
|
|
41
|
+
add: derived(add(service)),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
let feature = makeFeature(service)
|
|
45
|
+
feature.add(4)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Anti-Pattern (Avoid)
|
|
49
|
+
|
|
50
|
+
```rescript
|
|
51
|
+
open Tilia
|
|
52
|
+
|
|
53
|
+
// Avoid: logic-heavy body inside carve.
|
|
54
|
+
let cart = carve(({derived}) => {
|
|
55
|
+
items: [{price: 10.0, quantity: 1}],
|
|
56
|
+
total: derived(self => {
|
|
57
|
+
let mutable sum = 0.0
|
|
58
|
+
for i in 0 to Array.length(self.items) - 1 {
|
|
59
|
+
switch self.items[i] {
|
|
60
|
+
| Some(item) => sum = sum +. item.price *. Float.fromInt(item.quantity)
|
|
61
|
+
| None => ()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
sum
|
|
65
|
+
}),
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Feature File Organization
|
|
70
|
+
|
|
71
|
+
Use this if the project does not provide other guidelines.
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
[feature-name]/
|
|
75
|
+
index.res // carve glue
|
|
76
|
+
type.res // type of the feature
|
|
77
|
+
computed.res // all computed/derived values
|
|
78
|
+
actions.res // all mutating functions
|
|
79
|
+
service.res // external dependencies (db fetch, etc)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Full API Map (ReScript)
|
|
83
|
+
|
|
84
|
+
### `tilia`
|
|
85
|
+
|
|
86
|
+
Wrap an object/array into a reactive proxy.
|
|
87
|
+
|
|
88
|
+
```rescript
|
|
89
|
+
let state = tilia({count: 0})
|
|
90
|
+
state.count = 1
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### `carve`
|
|
94
|
+
|
|
95
|
+
Create a reactive feature object with helper-function injection via `derived`.
|
|
96
|
+
|
|
97
|
+
```rescript
|
|
98
|
+
type feature = {value: int, doubled: int}
|
|
99
|
+
let doubled = (self: feature) => self.value * 2
|
|
100
|
+
|
|
101
|
+
let feature = carve(({derived}) => {
|
|
102
|
+
value: 1,
|
|
103
|
+
doubled: derived(doubled),
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `observe`
|
|
108
|
+
|
|
109
|
+
Push reactivity. Callback re-runs when tracked reads change.
|
|
110
|
+
|
|
111
|
+
```rescript
|
|
112
|
+
observe(() => Js.log(state.count))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### `watch`
|
|
116
|
+
|
|
117
|
+
Split tracking and effect.
|
|
118
|
+
|
|
119
|
+
```rescript
|
|
120
|
+
watch(
|
|
121
|
+
() => state.count,
|
|
122
|
+
v => Js.log(v),
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### `batch`
|
|
127
|
+
|
|
128
|
+
Group writes and flush once.
|
|
129
|
+
|
|
130
|
+
```rescript
|
|
131
|
+
batch(() => {
|
|
132
|
+
state.a = 1
|
|
133
|
+
state.b = 2
|
|
134
|
+
})
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### `signal`
|
|
138
|
+
|
|
139
|
+
Single mutable reactive value + setter.
|
|
140
|
+
|
|
141
|
+
```rescript
|
|
142
|
+
let (count, setCount) = signal(0)
|
|
143
|
+
setCount(2)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### `derived` (signal API)
|
|
147
|
+
|
|
148
|
+
Create a derived signal from signals or reactive reads.
|
|
149
|
+
|
|
150
|
+
```rescript
|
|
151
|
+
let (a, setA) = signal(1)
|
|
152
|
+
let b = derived(() => a.value * 2)
|
|
153
|
+
setA(2)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `lift`
|
|
157
|
+
|
|
158
|
+
Insert signal value into a `tilia` object.
|
|
159
|
+
|
|
160
|
+
```rescript
|
|
161
|
+
let (s, setS) = signal(0)
|
|
162
|
+
let state = tilia({count: lift(s), setS})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### `readonly`
|
|
166
|
+
|
|
167
|
+
Insert non-tracked immutable data wrapper.
|
|
168
|
+
|
|
169
|
+
```rescript
|
|
170
|
+
let app = tilia({form: readonly(bigData)})
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### `computed`
|
|
174
|
+
|
|
175
|
+
Pull reactivity. Re-computes on read after dependency invalidation.
|
|
176
|
+
|
|
177
|
+
```rescript
|
|
178
|
+
let state = tilia({
|
|
179
|
+
count: 1,
|
|
180
|
+
double: computed(() => state.count * 2),
|
|
181
|
+
})
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### `source` (async query and re-query)
|
|
185
|
+
|
|
186
|
+
Use `source(initial, setup)` for async loaders and re-loaders.
|
|
187
|
+
|
|
188
|
+
- `initial` is returned until `set` is called.
|
|
189
|
+
- `setup(previous, set)` runs on first read.
|
|
190
|
+
- `setup(previous, set)` runs again when tracked dependencies inside setup change.
|
|
191
|
+
- `set(next)` updates the source value imperatively.
|
|
192
|
+
- `previous` is the last emitted value, useful for incremental updates.
|
|
193
|
+
- `previous` also supports stale-while-revalidate UI (keep old data visible, e.g. greyed out, while reloading to avoid blinking).
|
|
194
|
+
|
|
195
|
+
```rescript
|
|
196
|
+
open Tilia
|
|
197
|
+
|
|
198
|
+
let sleep: unit => promise<unit> = async () =>
|
|
199
|
+
%raw(`new Promise(resolve => setTimeout(resolve, 10))`)
|
|
200
|
+
|
|
201
|
+
let (query, setQuery) = signal("helena")
|
|
202
|
+
|
|
203
|
+
let fetchName = async (q, previous, set) => {
|
|
204
|
+
await sleep()
|
|
205
|
+
switch q {
|
|
206
|
+
| "helena" => set("Helena")
|
|
207
|
+
| "bob" => set("William")
|
|
208
|
+
| _ => set(previous ++ "+" ++ q)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
let user = tilia({
|
|
213
|
+
name: source("Loading", fetchName(query.value, ...)),
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
// Re-query
|
|
217
|
+
setQuery("bob")
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### `source` + `derived` inside `carve` (conditional loader strategy)
|
|
221
|
+
|
|
222
|
+
```rescript
|
|
223
|
+
open Tilia
|
|
224
|
+
|
|
225
|
+
let loader = service => self => async (previous, set) => {
|
|
226
|
+
set(stale(previous))
|
|
227
|
+
let project = await service.loadProject(self.projectId)
|
|
228
|
+
set(loaded(project))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let selectProject = self => id => self.projectId = id
|
|
232
|
+
|
|
233
|
+
let projectBranch = carve(({derived}) => {
|
|
234
|
+
projectId: "main",
|
|
235
|
+
project: source(empty(), derived(loader(service))),
|
|
236
|
+
selectProject: derived(selectProject),
|
|
237
|
+
})
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Use this when loading depends on feature fields (`self.projectId`) and keep `previous` to preserve old UI data until new values are ready.
|
|
241
|
+
|
|
242
|
+
### `store`
|
|
243
|
+
|
|
244
|
+
Managed state with setup returning current value and receiving a setter.
|
|
245
|
+
|
|
246
|
+
```rescript
|
|
247
|
+
type auth = LoggedOut | Loading | LoggedIn
|
|
248
|
+
|
|
249
|
+
let machine = set => LoggedOut
|
|
250
|
+
let app = tilia({auth: store(machine)})
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### `make`
|
|
254
|
+
|
|
255
|
+
Create isolated Tilia context (`tilia`, `carve`, `observe`, etc.).
|
|
256
|
+
|
|
257
|
+
```rescript
|
|
258
|
+
let ctx = make()
|
|
259
|
+
let local = ctx.tilia({count: 0})
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Generation Rules for AI
|
|
263
|
+
|
|
264
|
+
- Prefer `carve` over ad-hoc `tilia` for feature modules.
|
|
265
|
+
- Keep `carve` declarative and short.
|
|
266
|
+
- Extract domain logic into external functions.
|
|
267
|
+
- Functions wired with `derived` take `self` first.
|
|
268
|
+
- Use `source` for async query/re-query flows.
|
|
269
|
+
- Explain `set` as imperative emitter and `previous` as last emitted value.
|
|
270
|
+
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# Tilia LLM Guide (TypeScript)
|
|
2
|
+
|
|
3
|
+
AI-focused TypeScript documentation for the full Tilia API.
|
|
4
|
+
|
|
5
|
+
## Primary Rule
|
|
6
|
+
|
|
7
|
+
- Use `carve` as the default for feature modules.
|
|
8
|
+
- `carve` binds a feature into one reactive object.
|
|
9
|
+
- `carve` must stay glue-only and avoid domain complexity.
|
|
10
|
+
- Put behavior in standalone arrow functions that accept `self`.
|
|
11
|
+
- Bind with `field: derived(field)` where possible.
|
|
12
|
+
|
|
13
|
+
## Canonical Carve Pattern
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { carve, source } from "tilia";
|
|
17
|
+
|
|
18
|
+
type Feature = {
|
|
19
|
+
count: number;
|
|
20
|
+
double: number;
|
|
21
|
+
add: (count: number) => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type Service = {
|
|
25
|
+
fetchCount: () => (previous: number, set: (value: number) => void) => void;
|
|
26
|
+
updateCount: (next: number, rollback: () => void) => void;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const double = (self: Feature): number => self.count * 2;
|
|
30
|
+
|
|
31
|
+
const add =
|
|
32
|
+
(service: Service) =>
|
|
33
|
+
(self: Feature) =>
|
|
34
|
+
(count: number): void => {
|
|
35
|
+
const prevValue = self.count;
|
|
36
|
+
self.count += count; // optimistic write
|
|
37
|
+
service.updateCount(self.count, () => (self.count = prevValue));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const makeFeature = (service: Service) =>
|
|
41
|
+
carve<Feature>(({ derived }) => ({
|
|
42
|
+
count: source(0, service.fetchCount()),
|
|
43
|
+
double: derived(double),
|
|
44
|
+
add: derived(add(service)),
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
const feature = makeFeature(service);
|
|
48
|
+
feature.add(4);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Anti-Pattern (Avoid)
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { carve } from "tilia";
|
|
55
|
+
|
|
56
|
+
// Avoid: logic-heavy body inside carve.
|
|
57
|
+
const feature = carve(({ derived }) => ({
|
|
58
|
+
count: 0,
|
|
59
|
+
double: derived((self) => {
|
|
60
|
+
let acc = 0;
|
|
61
|
+
for (let i = 0; i < self.count; i++) acc += 2;
|
|
62
|
+
return acc;
|
|
63
|
+
}),
|
|
64
|
+
}));
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Feature File Organization
|
|
68
|
+
|
|
69
|
+
Use this if the project does not provide other guidelines.
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
[feature-name]/
|
|
73
|
+
index.ts // carve glue
|
|
74
|
+
type.ts // ts type of the feature
|
|
75
|
+
computed.ts // all computed/derived values
|
|
76
|
+
actions.ts // all mutating functions
|
|
77
|
+
service.ts // external dependencies (db fetch, etc)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Full API Map (TypeScript)
|
|
81
|
+
|
|
82
|
+
### `tilia`
|
|
83
|
+
|
|
84
|
+
Wrap object/array into reactive proxy.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { tilia } from "tilia";
|
|
88
|
+
const state = tilia({ count: 0 });
|
|
89
|
+
state.count = 1;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### `carve`
|
|
93
|
+
|
|
94
|
+
Create feature object and inject `self` via `derived`.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { carve } from "tilia";
|
|
98
|
+
|
|
99
|
+
type Feature = { value: number; doubled: number };
|
|
100
|
+
const doubled = (self: Feature): number => self.value * 2;
|
|
101
|
+
|
|
102
|
+
const feature = carve<Feature>(({ derived }) => ({
|
|
103
|
+
value: 1,
|
|
104
|
+
doubled: derived(doubled),
|
|
105
|
+
}));
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### `observe`
|
|
109
|
+
|
|
110
|
+
Push reactivity callback.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { observe } from "tilia";
|
|
114
|
+
observe(() => console.log(state.count));
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### `watch`
|
|
118
|
+
|
|
119
|
+
Capture and effect separation.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { watch } from "tilia";
|
|
123
|
+
watch(
|
|
124
|
+
() => state.count,
|
|
125
|
+
(value) => console.log(value),
|
|
126
|
+
);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### `batch`
|
|
130
|
+
|
|
131
|
+
Group writes and flush once.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { batch } from "tilia";
|
|
135
|
+
batch(() => {
|
|
136
|
+
state.a = 1;
|
|
137
|
+
state.b = 2;
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `signal`
|
|
142
|
+
|
|
143
|
+
Single mutable reactive value and setter.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { signal } from "tilia";
|
|
147
|
+
const [count, setCount] = signal(0);
|
|
148
|
+
setCount(2);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### `derived` (signal API)
|
|
152
|
+
|
|
153
|
+
Derived signal from signals/reactive reads.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { signal, derived } from "tilia";
|
|
157
|
+
const [a, setA] = signal(1);
|
|
158
|
+
const b = derived(() => a.value * 2);
|
|
159
|
+
setA(2);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### `lift`
|
|
163
|
+
|
|
164
|
+
Expose signal in object as reactive value.
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import { signal, lift, tilia } from "tilia";
|
|
168
|
+
const [s, setS] = signal(0);
|
|
169
|
+
const state = tilia({ count: lift(s), setS });
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### `readonly`
|
|
173
|
+
|
|
174
|
+
Insert immutable data wrapper without tracking inner mutations.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { tilia, readonly } from "tilia";
|
|
178
|
+
const app = tilia({ form: readonly({ version: 1 }) });
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### `computed`
|
|
182
|
+
|
|
183
|
+
Pull-based derived value with cache + invalidation.
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { computed, tilia } from "tilia";
|
|
187
|
+
const state = tilia({
|
|
188
|
+
count: 1,
|
|
189
|
+
double: computed(() => state.count * 2),
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### `source` (async query and re-query)
|
|
194
|
+
|
|
195
|
+
Use `source(initial, setup)` for async loading and re-loading.
|
|
196
|
+
|
|
197
|
+
- `initial` is returned before first `set`.
|
|
198
|
+
- `setup(previous, set)` runs on first read.
|
|
199
|
+
- `setup(previous, set)` runs again when tracked dependencies in setup change.
|
|
200
|
+
- `set(next)` imperatively publishes a new value.
|
|
201
|
+
- `previous` is the latest emitted value, useful for incremental updates.
|
|
202
|
+
- `previous` also supports stale-while-revalidate UI (keep old data visible, e.g. greyed out, while reloading to avoid blinking).
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { signal, tilia, source } from "tilia";
|
|
206
|
+
|
|
207
|
+
const sleep = () => new Promise((resolve) => setTimeout(resolve, 10));
|
|
208
|
+
const [query, setQuery] = signal("helena");
|
|
209
|
+
|
|
210
|
+
const fetchName =
|
|
211
|
+
(q: string) =>
|
|
212
|
+
async (previous: string, set: (value: string) => void): Promise<void> => {
|
|
213
|
+
await sleep();
|
|
214
|
+
if (q === "helena") set("Helena");
|
|
215
|
+
else if (q === "bob") set("William");
|
|
216
|
+
else set(`${previous}+${q}`);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const user = tilia({
|
|
220
|
+
name: source("Loading", fetchName(query.value)),
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// Re-query
|
|
224
|
+
setQuery("bob");
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### `source` + `derived` inside `carve` (conditional loader strategy)
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
const loader =
|
|
231
|
+
(service: Service) =>
|
|
232
|
+
(self: { projectId: string }) =>
|
|
233
|
+
async (previous: Project, set: (value: Project) => void) => {
|
|
234
|
+
set(stale(previous));
|
|
235
|
+
const project = await service.loadProject(self.projectId);
|
|
236
|
+
set(loaded(project));
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const selectProject = (self: ProjectBranch) => (id: string) => {
|
|
240
|
+
self.projectId = id;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const projectBranch = carve<ProjectBranch>(({ derived }) => ({
|
|
244
|
+
projectId: "main",
|
|
245
|
+
project: source(empty(), derived(loader(service))),
|
|
246
|
+
selectProject: derived(selectProject),
|
|
247
|
+
}));
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Use this when loading depends on feature fields (`self.projectId`) and keep `previous` to preserve old UI data until new values are ready.
|
|
251
|
+
|
|
252
|
+
### `store`
|
|
253
|
+
|
|
254
|
+
Managed value with setup that returns current state and receives setter.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { tilia, store } from "tilia";
|
|
258
|
+
type Auth = { t: "LoggedOut" } | { t: "LoggedIn" };
|
|
259
|
+
const auth = (set: (next: Auth) => void): Auth => ({ t: "LoggedOut" });
|
|
260
|
+
const app = tilia({ auth: store(auth) });
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### `make`
|
|
264
|
+
|
|
265
|
+
Create isolated Tilia context.
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import { make } from "tilia";
|
|
269
|
+
const ctx = make();
|
|
270
|
+
const local = ctx.tilia({ count: 0 });
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Generation Rules for AI
|
|
274
|
+
|
|
275
|
+
- Prefer `carve` for feature boundaries.
|
|
276
|
+
- Keep `carve` declarative and short.
|
|
277
|
+
- Use arrow functions for helper logic.
|
|
278
|
+
- Helpers wired through `derived` must accept `self`.
|
|
279
|
+
- Use `source` for async query/re-query flows.
|
|
280
|
+
- Explain `set` as imperative emission and `previous` as last emitted value.
|
|
281
|
+
|
package/llms.txt
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Tilia LLM Docs
|
|
2
|
+
|
|
3
|
+
This index is optimized for AI agents and coding assistants.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [ReScript guide](./llms-rescript.md)
|
|
8
|
+
2. [TypeScript guide](./llms-typescript.md)
|
|
9
|
+
|
|
10
|
+
## How AI Should Use These Docs
|
|
11
|
+
|
|
12
|
+
1. Read this file first.
|
|
13
|
+
2. Load the language-specific guide.
|
|
14
|
+
3. Follow the carve-first rules strictly.
|
|
15
|
+
4. Prefer simple, testable composition over inline reactive complexity.
|
|
16
|
+
|
|
17
|
+
## Non-Negotiable Rules
|
|
18
|
+
|
|
19
|
+
- Use `carve` as the default way to build feature modules.
|
|
20
|
+
- `carve` must bind parts into one reactive object, not contain business logic.
|
|
21
|
+
- Keep `carve(({ derived }) => ({ ... }))` glue-only.
|
|
22
|
+
- Move logic into standalone functions, then inject `self` via `derived`.
|
|
23
|
+
- Prefer `name: derived(name)` where `name` takes `self` as first parameter.
|
|
24
|
+
- In TypeScript examples, prefer arrow functions to keep dependency injection paths clean.
|
|
25
|
+
|
|
26
|
+
## API Anchors
|
|
27
|
+
|
|
28
|
+
- `carve: (deriver<'a> => 'a) => 'a`
|
|
29
|
+
- `deriver.derived: ('p => 'a) => 'a`
|
|
30
|
+
- `computed: (unit => 'a) => 'a`
|
|
31
|
+
- `source: ('a, ('a, 'a => unit) => 'ignored) => 'a`
|
|
32
|
+
- `store: (('a => unit) => 'a) => 'a`
|
|
33
|
+
- `tilia: 'a => 'a`
|
|
34
|
+
|
|
35
|
+
## Coverage Requirement for AI
|
|
36
|
+
|
|
37
|
+
- Treat `llms-rescript.md` and `llms-typescript.md` as full API references.
|
|
38
|
+
- Cover: `tilia`, `carve`, `observe`, `watch`, `batch`, `signal`, `derived`, `lift`, `readonly`, `computed`, `source`, `store`, `make`.
|
|
39
|
+
- For `source`, always explain:
|
|
40
|
+
- setup runs on first read
|
|
41
|
+
- setup re-runs when tracked dependencies change
|
|
42
|
+
- `set` emits the next value imperatively
|
|
43
|
+
- `previous` is the last emitted value
|
|
44
|
+
- recommended example: `source(empty(), derived(loader(service)))` where loader sets `stale(previous)` before async fetch
|
|
45
|
+
- when used with `carve` + `derived(loader)`, `previous` should be used to keep stale UI data visible during reload (no blink)
|
|
46
|
+
- the `derived(loader)` pattern enables conditional loader strategies based on sibling feature fields
|
|
47
|
+
|