brumate 0.8.0 → 0.9.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/dist/{boot-BkUdiYOF.d.ts → boot-ej-9NRT3.d.ts} +20 -2
- package/dist/cli.js +88 -82
- package/dist/cli.js.map +1 -1
- package/dist/{client-B0FXW5Kw.js → client-B-ww-PQ7.js} +402 -63
- package/dist/client-B-ww-PQ7.js.map +1 -0
- package/dist/{client-Cq6aTiDs.d.ts → client-Do6IBIhI.d.ts} +58 -14
- package/dist/{defer-BMIMP4Hq.js → defer-JD2FK9mV.js} +5 -3
- package/dist/defer-JD2FK9mV.js.map +1 -0
- package/dist/{devtools-calls-DGW6nLZ2.js → devtools-calls-DCjuSkim.js} +3 -3
- package/dist/{devtools-calls-DGW6nLZ2.js.map → devtools-calls-DCjuSkim.js.map} +1 -1
- package/dist/{devtools-panel-B1nF1KB7.js → devtools-panel-DLeWTPhU.js} +4 -4
- package/dist/{devtools-panel-B1nF1KB7.js.map → devtools-panel-DLeWTPhU.js.map} +1 -1
- package/dist/{devtools-B4prrxht.js → devtools-tuq7ATGN.js} +10 -7
- package/dist/devtools-tuq7ATGN.js.map +1 -0
- package/dist/{error-catalog-DakxjSgj.js → error-catalog-BBWB7w-E.js} +11 -4
- package/dist/error-catalog-BBWB7w-E.js.map +1 -0
- package/dist/{error-catalog-VxLbz-6p.js → error-catalog-CbmQqfat.js} +1 -1
- package/dist/{events-LgLdp1R7.js → events-BDVITj3P.js} +3 -5
- package/dist/events-BDVITj3P.js.map +1 -0
- package/dist/{features-DwMYKBIC.js → features-Cte5aj20.js} +8 -2
- package/dist/features-Cte5aj20.js.map +1 -0
- package/dist/{files-D5GtxwEQ.js → files-Bz0lAQzD.js} +2 -2
- package/dist/{files-D5GtxwEQ.js.map → files-Bz0lAQzD.js.map} +1 -1
- package/dist/{html-Cf5uKhLs.js → html-BYuHDvxy.js} +10 -3
- package/dist/html-BYuHDvxy.js.map +1 -0
- package/dist/index.d.ts +71 -19
- package/dist/index.js +3 -3
- package/dist/{inspect-CGl5Y8q6.js → inspect-fpaBJ5pm.js} +1305 -75
- package/dist/inspect-fpaBJ5pm.js.map +1 -0
- package/dist/{loader-BsaSuIoG.js → loader-DMxuZ6He.js} +14 -6
- package/dist/loader-DMxuZ6He.js.map +1 -0
- package/dist/{navigate-BlowKvhB.js → navigate-C5PjwYMh.js} +108 -20
- package/dist/navigate-C5PjwYMh.js.map +1 -0
- package/dist/{produce-CLABZ8k2.d.ts → produce-BDkCsGH7.d.ts} +3 -3
- package/dist/{rpc-C1jYVNAe.js → rpc-DOdrekhP.js} +23 -13
- package/dist/rpc-DOdrekhP.js.map +1 -0
- package/dist/runtime/bundles.d.ts +3 -2
- package/dist/runtime/bundles.js +20 -5
- package/dist/runtime/bundles.js.map +1 -1
- package/dist/runtime/client.d.ts +4 -3
- package/dist/runtime/client.js +5 -5
- package/dist/runtime/devtools.d.ts +3 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/events.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/otel.d.ts +18 -0
- package/dist/runtime/otel.js +127 -0
- package/dist/runtime/otel.js.map +1 -0
- package/dist/runtime/server.d.ts +4 -3
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +2 -2
- package/dist/runtime/signals.js +4 -1
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -2
- package/dist/runtime/store.js +1 -1
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/search-params-qGERTLi3.js +382 -0
- package/dist/search-params-qGERTLi3.js.map +1 -0
- package/dist/{serial-ribg9NAj.js → serial-B2AJ9VGx.js} +1 -1
- package/dist/{serial-ioa17MuY.js → serial-Cj6pDGOq.js} +6 -6
- package/dist/{serial-ioa17MuY.js.map → serial-Cj6pDGOq.js.map} +1 -1
- package/dist/{server-DesBZv5g.d.ts → server-2-LS_KFo.d.ts} +125 -9
- package/dist/{server-BUuf7XPZ.js → server-CRGZMWnK.js} +545 -236
- package/dist/server-CRGZMWnK.js.map +1 -0
- package/dist/{shared-CX_YacDm.js → shared-CUBWrbiM.js} +4 -4
- package/dist/{shared-CX_YacDm.js.map → shared-CUBWrbiM.js.map} +1 -1
- package/dist/sheets-B9Zr50mf.js +105 -0
- package/dist/sheets-B9Zr50mf.js.map +1 -0
- package/dist/{signals-7VVD9C_H.d.ts → signals-BgsJK-uT.d.ts} +16 -6
- package/dist/{static-loader-C_en-4v8.js → static-loader-BDBtWsdg.js} +107 -19
- package/dist/static-loader-BDBtWsdg.js.map +1 -0
- package/dist/{static-loader-UKnK11Em.d.ts → static-loader-CAFn6p0l.d.ts} +2 -2
- package/dist/{store-9_oa0HG1.d.ts → store-BwWg-Iei.d.ts} +79 -2
- package/dist/store-DNr24Z8L.js +950 -0
- package/dist/store-DNr24Z8L.js.map +1 -0
- package/dist/{stream-read-BTsYstJY.js → stream-read-CiLDH60b.js} +2 -2
- package/dist/{stream-read-BTsYstJY.js.map → stream-read-CiLDH60b.js.map} +1 -1
- package/dist/{stream-read-Dek3HnqO.js → stream-read-DVoregpA.js} +1 -1
- package/dist/trace-DT7RGRAV.d.ts +52 -0
- package/dist/trace-browser-C7MFMove.js +170 -0
- package/dist/trace-browser-C7MFMove.js.map +1 -0
- package/dist/trace-flag-Dy267snx.js +7 -0
- package/dist/trace-flag-Dy267snx.js.map +1 -0
- package/dist/{trusted-g_zUJbh2.js → trusted-Bmwg4_hf.js} +12 -5
- package/dist/trusted-Bmwg4_hf.js.map +1 -0
- package/dist/view-transitions-BpnVwtS4.js +141 -0
- package/dist/view-transitions-BpnVwtS4.js.map +1 -0
- package/dist/vite.d.ts +8 -1
- package/dist/vite.js +356 -46
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +8 -0
- package/package.json +13 -1
- package/skills/brumate/SKILL.md +9 -5
- package/skills/brumate/references/errors.md +95 -14
- package/skills/brumate/references/events.md +27 -1
- package/skills/brumate/references/signals.md +4 -4
- package/skills/brumate/references/state.md +79 -4
- package/skills/brumate/references/syntax.md +58 -9
- package/dist/client-B0FXW5Kw.js.map +0 -1
- package/dist/defer-BMIMP4Hq.js.map +0 -1
- package/dist/devtools-B4prrxht.js.map +0 -1
- package/dist/error-catalog-DakxjSgj.js.map +0 -1
- package/dist/events-LgLdp1R7.js.map +0 -1
- package/dist/features-DwMYKBIC.js.map +0 -1
- package/dist/html-Cf5uKhLs.js.map +0 -1
- package/dist/inspect-CGl5Y8q6.js.map +0 -1
- package/dist/loader-BsaSuIoG.js.map +0 -1
- package/dist/navigate-BlowKvhB.js.map +0 -1
- package/dist/rpc-C1jYVNAe.js.map +0 -1
- package/dist/search-params-Wg-0FsMj.js +0 -148
- package/dist/search-params-Wg-0FsMj.js.map +0 -1
- package/dist/server-BUuf7XPZ.js.map +0 -1
- package/dist/static-loader-C_en-4v8.js.map +0 -1
- package/dist/store-Cy4EEyZ7.js +0 -439
- package/dist/store-Cy4EEyZ7.js.map +0 -1
- package/dist/trusted-g_zUJbh2.js.map +0 -1
package/elements.d.ts
CHANGED
|
@@ -526,6 +526,10 @@ export type GlobalAttributes<E> = Handlers<E> &
|
|
|
526
526
|
popover?: Attr<boolean | '' | Keyword<'auto' | 'manual' | 'hint'>>;
|
|
527
527
|
spellcheck?: Attr<boolean | '' | Keyword<'true' | 'false'>>;
|
|
528
528
|
tabindex?: Attr<Num>;
|
|
529
|
+
/** A class for the element in a view transition. It is named only while a transition runs. */
|
|
530
|
+
viewTransition?: Attr<string>;
|
|
531
|
+
/** The name of the element in a view transition, to pair it with one of the next page. */
|
|
532
|
+
viewTransitionName?: Attr<string>;
|
|
529
533
|
translate?: Attr<'' | Keyword<'yes' | 'no'>>;
|
|
530
534
|
writingsuggestions?: Attr<boolean | '' | Keyword<'true' | 'false'>>;
|
|
531
535
|
autocorrect?: Attr<boolean | '' | Keyword<'on' | 'off'>>;
|
|
@@ -1222,6 +1226,10 @@ export interface Elements {
|
|
|
1222
1226
|
referrerpolicy?: Attr<Referrer>;
|
|
1223
1227
|
fetchpriority?: Attr<Keyword<'high' | 'low' | 'auto'>>;
|
|
1224
1228
|
blocking?: Attr<'render' | (string & {})>;
|
|
1229
|
+
/** Marks code that is written in the file, between the tags. The compiler does not read it. */
|
|
1230
|
+
inline?: Attr<boolean>;
|
|
1231
|
+
/** When the script of a `src` or `inline` runs. Without it, a script outside `#head` runs at `load`. */
|
|
1232
|
+
trigger?: Attr<'idle' | 'visible' | 'interaction' | 'load'>;
|
|
1225
1233
|
}
|
|
1226
1234
|
>;
|
|
1227
1235
|
search: Html<'search'>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brumate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A component language and compiler for resumable web apps",
|
|
5
5
|
"homepage": "https://github.com/lxsmnsyc/brumate",
|
|
6
6
|
"bugs": "https://github.com/lxsmnsyc/brumate/issues",
|
|
@@ -89,6 +89,10 @@
|
|
|
89
89
|
"types": "./dist/runtime/values.d.ts",
|
|
90
90
|
"default": "./dist/runtime/values.js"
|
|
91
91
|
},
|
|
92
|
+
"./otel": {
|
|
93
|
+
"types": "./dist/runtime/otel.d.ts",
|
|
94
|
+
"default": "./dist/runtime/otel.js"
|
|
95
|
+
},
|
|
92
96
|
"./highlight": {
|
|
93
97
|
"types": "./dist/highlight.d.ts",
|
|
94
98
|
"default": "./dist/highlight.js"
|
|
@@ -145,8 +149,11 @@
|
|
|
145
149
|
"seroval-plugins": "^1.8.0"
|
|
146
150
|
},
|
|
147
151
|
"devDependencies": {
|
|
152
|
+
"@opentelemetry/api": "^1.10.0",
|
|
153
|
+
"@opentelemetry/sdk-trace-base": "^2.12.0",
|
|
148
154
|
"@oxc-project/types": "^0.154.0",
|
|
149
155
|
"@types/node": "^24.0.0",
|
|
156
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
150
157
|
"axe-core": "^4.14.0",
|
|
151
158
|
"happy-dom": "^20.14.6",
|
|
152
159
|
"less": "^4.9.1",
|
|
@@ -158,12 +165,16 @@
|
|
|
158
165
|
"vitest": "^5.0.4"
|
|
159
166
|
},
|
|
160
167
|
"peerDependencies": {
|
|
168
|
+
"@opentelemetry/api": ">=1.9",
|
|
161
169
|
"axe-core": ">=4.8",
|
|
162
170
|
"less": ">=4",
|
|
163
171
|
"sass": ">=1.70",
|
|
164
172
|
"vite": "^8.0.0"
|
|
165
173
|
},
|
|
166
174
|
"peerDependenciesMeta": {
|
|
175
|
+
"@opentelemetry/api": {
|
|
176
|
+
"optional": true
|
|
177
|
+
},
|
|
167
178
|
"axe-core": {
|
|
168
179
|
"optional": true
|
|
169
180
|
},
|
|
@@ -186,6 +197,7 @@
|
|
|
186
197
|
},
|
|
187
198
|
"scripts": {
|
|
188
199
|
"build": "tsdown",
|
|
200
|
+
"coverage": "echo 'The tests run with every feature flag on. The off path of a flag runs only in feature-flags-off.test.ts and e2e.' && vitest run --coverage --testTimeout=60000 --hookTimeout=60000",
|
|
189
201
|
"test": "vitest run",
|
|
190
202
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.elements.json"
|
|
191
203
|
}
|
package/skills/brumate/SKILL.md
CHANGED
|
@@ -32,15 +32,19 @@ A `.brm` file is a component: scripts for its state, an optional `<style>`, and
|
|
|
32
32
|
- Write a branch on the line of the closing brace, as the style: `} #else if (…) {` and `} #else {`. The compiler also accepts `#else` on the next line.
|
|
33
33
|
- A `#for` has a key: `#for (item, index of items by item.id) { … }`. Without `by`, each item is its own key.
|
|
34
34
|
- `$effect` never runs on mount. Its first run is after the first change of a value it reads. Code that must run when the page loads or comes into view is `$client(callback, trigger)`. The default trigger is `'visible'`.
|
|
35
|
-
- Reach for a handler first, then `$memo`, and `$effect` last. An effect is only for work outside the page's state, such as an element method, a cookie, `document.title`, a timer or a library. Never write an effect that only sets a signal from other signals: that value is a `$memo`, or a write in the handler.
|
|
35
|
+
- Reach for a handler first, then `$memo`, and `$effect` last. An effect is only for work outside the page's state, such as an element method, a cookie, `document.title`, a timer or a library. Never write an effect that only sets a signal from other signals: that value is a `$memo`, or a write in the handler. The compiler warns about it with BRM209.
|
|
36
|
+
- The callback of `$effect` and `$client` can be `async`, and returns its cleanup after the `await`: `return async () => await connection.close()`. Reads after an `await` are dependencies too.
|
|
36
37
|
- An element that browser code needs is `ref=$bind(name)`, where `name` is a signal. A bare `ref=name` is an error.
|
|
37
38
|
- To let a child write a value, destructure its prop with `let` and type it `Bindable<T>`. The parent passes `$bind(signal)`.
|
|
38
39
|
- A component never receives a signal. A function prop writes the parent's value: `onChange=((next) => (count = next))`.
|
|
39
40
|
- Markup is never a value in code or in an attribute. Use `#template name(parameters) { … }` and call it as `{name(arguments)}`.
|
|
40
41
|
- Browser wrappers of a handler come from `brumate/events`: `prevent`, `stop`, `once`, `capture`, `transition`. Write them in the attribute, with keys as string literals. `prevent(handler, 'Enter')` prevents only Enter with Ctrl, Meta and Alt up. `'Mod+ArrowDown'` names Ctrl or Meta. Calling `event.preventDefault()` in a handler is too late.
|
|
41
42
|
- A server function is an `async` function with `'use server'` on its first line. It reads no variable of the instance script. Pass values as arguments.
|
|
43
|
+
- To time the server, export `onTrace(span)` from `src/middleware.ts`, next to `onError`. It gets each finished span (`brumate.request`, `brumate.render`, `brumate.call` and others) and makes none when it is not exported. The browser takes `onTrace` in the options of `start`. `otel()` of `brumate/otel` is an `onTrace` for OpenTelemetry. See the page Observability in `website/docs` of the repository.
|
|
44
|
+
- `$signal` and `$memo` at the top level of a `.brm.ts` module or of `<script module>` give one value for the module, shared by its importers and by every request on the server. A component writes an imported one only through a function that the module exports.
|
|
45
|
+
- `viewTransition="name"` marks an element for a view transition of `transition(handler)` or of `navigate: { transition: true }`. `viewTransitionName=(expr)` pairs an element across two pages.
|
|
42
46
|
- A store computed from other stores is `derived(sources, fn)` of `brumate/store`, read with `$store`. It is one-way, and never goes in a provided value or a prop.
|
|
43
|
-
-
|
|
47
|
+
- A script in markup is `<script inline>…</script>`, with the code as written, or `<script src="…"></script>`. `trigger="idle"`, `"visible"`, `"interaction"` or `"load"` says when it loads. `data-rerun` runs a head script again after each client navigation. The script gets the nonce of the page.
|
|
44
48
|
- The light and dark choice of the page is `ColorScheme` and `colorScheme()` of `@brumate/ui`, not a signal and an effect.
|
|
45
49
|
- Do not use `$ref`, `$watch`, `$settled`, `$cleanup`, `$get`, `$set`, or modifiers such as `onSubmit:prevent`.
|
|
46
50
|
|
|
@@ -48,10 +52,10 @@ A `.brm` file is a component: scripts for its state, an optional `<style>`, and
|
|
|
48
52
|
|
|
49
53
|
Read the file for the part of the work that you do.
|
|
50
54
|
|
|
51
|
-
- [references/syntax.md](references/syntax.md): the parts of a file, attributes, props, children, templates, control flow,
|
|
55
|
+
- [references/syntax.md](references/syntax.md): the parts of a file, attributes, props, children, templates, control flow, styles, scripts in markup, module signals and `ColorScheme`.
|
|
52
56
|
- [references/signals.md](references/signals.md): every function of `brumate/signals`, with what it returns and where it goes.
|
|
53
|
-
- [references/state.md](references/state.md): signals, memos, async data, effects, `$client`, refs, context and derived stores.
|
|
54
|
-
- [references/events.md](references/events.md): handlers, the wrappers of `brumate/events`, and `$handler`.
|
|
57
|
+
- [references/state.md](references/state.md): signals, memos, `$produce` on maps and sets, async data, effects and async effects, `$client`, refs, context and derived stores.
|
|
58
|
+
- [references/events.md](references/events.md): handlers, the wrappers of `brumate/events`, view transitions and `$handler`.
|
|
55
59
|
- [references/errors.md](references/errors.md): every compile error, its cause, and the form to write instead.
|
|
56
60
|
|
|
57
61
|
## Checking your work
|
|
@@ -1241,18 +1241,6 @@ $effect(() => {
|
|
|
1241
1241
|
});
|
|
1242
1242
|
```
|
|
1243
1243
|
|
|
1244
|
-
## BRM096: The callback of {name} cannot be async
|
|
1245
|
-
|
|
1246
|
-
The callback of `$effect` or `$client` is `async`.
|
|
1247
|
-
|
|
1248
|
-
https://brumate-docs.vercel.app/docs/errors#brm096
|
|
1249
|
-
|
|
1250
|
-
```brm fragment
|
|
1251
|
-
$effect(() => {
|
|
1252
|
-
load(id).then((value) => (data = value));
|
|
1253
|
-
});
|
|
1254
|
-
```
|
|
1255
|
-
|
|
1256
1244
|
## BRM097: $effect takes one argument
|
|
1257
1245
|
|
|
1258
1246
|
`$effect` has more than one argument.
|
|
@@ -1470,9 +1458,9 @@ let title = $signal('');
|
|
|
1470
1458
|
title = 'New';
|
|
1471
1459
|
```
|
|
1472
1460
|
|
|
1473
|
-
## BRM117: Cannot assign to {kind} "{name}"
|
|
1461
|
+
## BRM117: Cannot assign to {kind} "{name}"{hint}
|
|
1474
1462
|
|
|
1475
|
-
Code writes a memo, a const prop or another value that cannot change.
|
|
1463
|
+
Code writes a memo, a const prop, a module signal of an import or another value that cannot change.
|
|
1476
1464
|
|
|
1477
1465
|
https://brumate-docs.vercel.app/docs/errors#brm117
|
|
1478
1466
|
|
|
@@ -2281,3 +2269,96 @@ https://brumate-docs.vercel.app/docs/errors#brm179
|
|
|
2281
2269
|
```brm fragment
|
|
2282
2270
|
export const STEP = 1;
|
|
2283
2271
|
```
|
|
2272
|
+
|
|
2273
|
+
## BRM211: {name} cannot be compiled in a module{reason}. {fix}
|
|
2274
|
+
|
|
2275
|
+
A module uses a form that its top-level values cannot compile: a compile-time function that needs a component, such as `$effect`, at the top level, a gate or timed value that awaits, a memo, gate or timed value that calls a function it cannot follow, a form with the wrong arguments, or a signal in a destructuring write.
|
|
2276
|
+
|
|
2277
|
+
https://brumate-docs.vercel.app/docs/errors#brm211
|
|
2278
|
+
|
|
2279
|
+
```brm fragment
|
|
2280
|
+
export let count = $signal(0);
|
|
2281
|
+
export const double = $memo(count * 2);
|
|
2282
|
+
```
|
|
2283
|
+
|
|
2284
|
+
## BRM208: "{name}" is a signal of {module}, and a file of plain code gets its store, not its value. {fix}
|
|
2285
|
+
|
|
2286
|
+
A `.ts` or `.js` file imports a signal or a memo that a module declares at its top level. TypeScript types it as its value, and it is a store.
|
|
2287
|
+
|
|
2288
|
+
https://brumate-docs.vercel.app/docs/errors#brm208
|
|
2289
|
+
|
|
2290
|
+
```brm fragment
|
|
2291
|
+
// cart.brm.ts
|
|
2292
|
+
export let items = $signal<number[]>([]);
|
|
2293
|
+
export function count(): number {
|
|
2294
|
+
return items.length;
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
// plain.ts
|
|
2298
|
+
import { count } from './cart.brm.ts';
|
|
2299
|
+
```
|
|
2300
|
+
|
|
2301
|
+
## BRM209: "{name}" is written only by this effect. Use {form}
|
|
2302
|
+
|
|
2303
|
+
A warning. An `$effect` only assigns signals that nothing else writes, so each signal is a memo written the long way, and the page updates twice for one change. With one assignment and no `if`, the message gives the memo. An effect with a call, an `await`, a cleanup or a signal that a handler, another effect or a `$bind` also writes stays quiet.
|
|
2304
|
+
|
|
2305
|
+
https://brumate-docs.vercel.app/docs/errors#brm209
|
|
2306
|
+
|
|
2307
|
+
```brm fragment
|
|
2308
|
+
let count = $signal(0);
|
|
2309
|
+
const message = $memo(`Clicked ${count} times`);
|
|
2310
|
+
```
|
|
2311
|
+
|
|
2312
|
+
## BRM212: A <script> with src is not inline. Give it src or inline, not both
|
|
2313
|
+
|
|
2314
|
+
A `<script>` in markup has both `src` and `inline`. `src` loads a file, and `inline` marks code that is written in the file.
|
|
2315
|
+
|
|
2316
|
+
https://brumate-docs.vercel.app/docs/errors#brm212
|
|
2317
|
+
|
|
2318
|
+
```brm fragment
|
|
2319
|
+
<script src="https://example.com/chat.js" trigger="idle"></script>
|
|
2320
|
+
```
|
|
2321
|
+
|
|
2322
|
+
## BRM213: A <script> with src has no code inside. Write the code in <script inline>
|
|
2323
|
+
|
|
2324
|
+
A `<script src>` in markup has text inside. The browser ignores it.
|
|
2325
|
+
|
|
2326
|
+
https://brumate-docs.vercel.app/docs/errors#brm213
|
|
2327
|
+
|
|
2328
|
+
```brm fragment
|
|
2329
|
+
<script inline trigger="idle">
|
|
2330
|
+
window.dataLayer = [];
|
|
2331
|
+
</script>
|
|
2332
|
+
```
|
|
2333
|
+
|
|
2334
|
+
## BRM214: The trigger of a <script> is a plain string: idle, visible, interaction or load
|
|
2335
|
+
|
|
2336
|
+
The `trigger` of a `<script>` in markup is code in braces, has no value, or names another trigger.
|
|
2337
|
+
|
|
2338
|
+
https://brumate-docs.vercel.app/docs/errors#brm214
|
|
2339
|
+
|
|
2340
|
+
```brm fragment
|
|
2341
|
+
<script src="https://example.com/chat.js" trigger="interaction"></script>
|
|
2342
|
+
```
|
|
2343
|
+
|
|
2344
|
+
## BRM215: A script in #head cannot wait to be visible, since no element follows it. Use idle or interaction
|
|
2345
|
+
|
|
2346
|
+
A `<script trigger="visible">` is in `#head`. `visible` waits for the element after the script to come into view.
|
|
2347
|
+
|
|
2348
|
+
https://brumate-docs.vercel.app/docs/errors#brm215
|
|
2349
|
+
|
|
2350
|
+
```brm fragment
|
|
2351
|
+
#head {
|
|
2352
|
+
<script src="https://example.com/chat.js" trigger="idle"></script>
|
|
2353
|
+
}
|
|
2354
|
+
```
|
|
2355
|
+
|
|
2356
|
+
## BRM216: A script with a trigger runs once per page, so data-rerun does not apply. Remove one of them
|
|
2357
|
+
|
|
2358
|
+
A `<script>` in markup has `trigger` and `data-rerun`. A script with a trigger never runs again after a navigation.
|
|
2359
|
+
|
|
2360
|
+
https://brumate-docs.vercel.app/docs/errors#brm216
|
|
2361
|
+
|
|
2362
|
+
```brm fragment
|
|
2363
|
+
<script src="https://example.com/chat.js" trigger="idle"></script>
|
|
2364
|
+
```
|
|
@@ -75,6 +75,32 @@ A handler runs after the event has finished dispatching, so the browser has acte
|
|
|
75
75
|
<ul onKeyDown=(prevent(move, 'NotAKey'))></ul>
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
## View transitions
|
|
79
|
+
|
|
80
|
+
`transition(handler)` runs the handler inside a view transition. The browser animates the elements that the page marks:
|
|
81
|
+
|
|
82
|
+
```brm
|
|
83
|
+
<script>
|
|
84
|
+
import { $signal } from 'brumate/signals';
|
|
85
|
+
import { transition } from 'brumate/events';
|
|
86
|
+
|
|
87
|
+
let items = $signal(['Ada', 'Grace', 'Linus']);
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<button onClick=(transition(() => (items = [...items].reverse())))>Reverse</button>
|
|
91
|
+
<ul>
|
|
92
|
+
#for (item of items by item) {
|
|
93
|
+
<li viewTransition="item">{item}</li>
|
|
94
|
+
}
|
|
95
|
+
</ul>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- `viewTransition="item"` is a class of the element, which CSS matches as `::view-transition-group(.item)`. Each marked element gets a name of its own while the transition runs, so an item that moves slides, a new one fades in and a removed one fades out.
|
|
99
|
+
- `viewTransitionName=(expr)` is the name, to pair an element of one page with the element of the next one: ``<img viewTransition="photo" viewTransitionName=(`photo-${photo.id}`) src={photo.src}>``.
|
|
100
|
+
- `brumate({ navigate: { transition: true } })` in the plugin options changes pages inside a view transition. The marks work there too.
|
|
101
|
+
- The transition holds the writes that the handler makes before its first `await`. `transition(handler, ...types)` gives types, which CSS matches with `:active-view-transition-type(type)`.
|
|
102
|
+
- A transition of a handler does not start with `prefers-reduced-motion`. A navigation does not check it, so switch the animation off in CSS.
|
|
103
|
+
|
|
78
104
|
## Cancel from a part
|
|
79
105
|
|
|
80
106
|
`cancelWhen(element, 'click' | 'submit', check)` from `brumate/events` cancels the event of the element or of an element inside it while `check(event)` returns true, before any brumate handler runs. It returns a function that removes the check. It calls `preventDefault()` and does not stop the event, so plain `addEventListener` listeners still run and can read `event.defaultPrevented`. An element inside a shadow root is not reached.
|
|
@@ -99,7 +125,7 @@ A function in a script is a handler only when markup uses it, so a spread leaves
|
|
|
99
125
|
}
|
|
100
126
|
|
|
101
127
|
const remove = (index: number) => ({
|
|
102
|
-
type: 'button',
|
|
128
|
+
type: 'button' as const,
|
|
103
129
|
'aria-label': `Remove ${items[index]}`,
|
|
104
130
|
onClick: $handler(prevent(removeAt), index),
|
|
105
131
|
});
|
|
@@ -37,7 +37,7 @@ The compiler replaces each call and removes the import, so none of them ship. Im
|
|
|
37
37
|
## What each one does
|
|
38
38
|
|
|
39
39
|
- `$props<T>()`: the props of the component. Destructure it: `const { title, size = 'm', ...rest } = $props<Props>()`. With `let`, the component writes the props, and `Bindable<T>` in the type marks one that a parent can bind. Not in a block script.
|
|
40
|
-
- `$signal(value)`: writable state. Read it and assign to it as a variable. The start value is computed once, on the server.
|
|
40
|
+
- `$signal(value)`: writable state. Read it and assign to it as a variable. The start value is computed once, on the server. At the top level of a `.brm.ts` module or of `<script module>`, `$signal` and `$memo` give one value for the module (see syntax.md).
|
|
41
41
|
- `$memo(expression)`: a read-only value that follows the values it reads. It can hold a promise, such as a server function call, and gives the settled value.
|
|
42
42
|
- `$gate(value, (prev, next) => boolean)`: a memo that takes the new value only when the guard returns true, and keeps its value otherwise. The first value passes. The value cannot be a promise: `await` and server calls are compile errors, other promises throw.
|
|
43
43
|
- `$debounced(value, ms)`: a memo that takes the value once it stops changing for `ms` milliseconds. `ms` is a number literal.
|
|
@@ -46,10 +46,10 @@ The compiler replaces each call and removes the import, so none of them ship. Im
|
|
|
46
46
|
- `$resolve(memo, { timeout, signal })`: waits until the memo is no longer pending, and gives its value. A handler that reads a memo that can lack a value uses `await $resolve(memo)` or checks `$isPending(memo)` first (BRM182).
|
|
47
47
|
- `$isPassed(prop)`: true when the caller passed the prop, also as `undefined` or `null`. A default value does not count. The argument is a prop that the component destructures.
|
|
48
48
|
- `$isBound(prop)`: true when the caller passed the prop with `$bind`, so a write changes the caller's value. The argument is a prop destructured with `let`.
|
|
49
|
-
- `$effect(callback)`: runs the callback in the browser when a value that it reads changes. Never on mount, never on the server. The callback takes no parameters and
|
|
50
|
-
- `$client(callback, trigger?)`: runs the callback in the browser once. The trigger is `'visible'` (default), `'idle'` or `'load'`.
|
|
49
|
+
- `$effect(callback)`: runs the callback in the browser when a value that it reads changes. Never on mount, never on the server. The callback takes no parameters and can be `async`. It can return a cleanup: a function, an async function, or an object with `[Symbol.dispose]` or `[Symbol.asyncDispose]`.
|
|
50
|
+
- `$client(callback, trigger?)`: runs the callback in the browser once. The trigger is `'visible'` (default), `'idle'` or `'load'`. The callback can be `async`, and can return a cleanup as `$effect` does.
|
|
51
51
|
- `$untrack(value)`: reads a value, or calls a function, without depending on it.
|
|
52
|
-
- `$produce(signal, recipe)`: changes a draft of an object or
|
|
52
|
+
- `$produce(signal, recipe)`: changes a draft of an object, array, `Map` or `Set` in a signal, and writes the result as a new value. The recipe can return a new value instead.
|
|
53
53
|
- `$setContext(context, value)`: gives a value of a context to the components inside. Create the context with `createContext` from `brumate/context`. The value is read once. A signal, memo, prop or `$bind` value that changes, read outside a function, is BRM196: put it in a store with `$toStore`.
|
|
54
54
|
- `$getContext(context, fallback?)`: reads a context from the nearest component above that provides it, and throws when none does. With a second argument it gives the fallback instead: `$getContext(Field, undefined)` is a read that may have no provider. A literal fallback is passed as it is. Other code runs only without a provider, once per read, and again in the browser when it renders the component.
|
|
55
55
|
- `$store(source)`: binds a store, any value with `get()`, `subscribe(listener)` (returns a function that stops it) and optionally `set(value)`, to a variable. The source gives a store: a key of the value of `$getContext` such as `$store(field.state)`, `$store($getContext(Level))` for a context that holds a store, an import, a prop, a value of `<script module>`, a call or `store(0)`. A context, `undefined` and `null` are no store (BRM199), and a source that gives no store when the page renders throws a `TypeError`. For a context that may have no provider, guard on the value: `const field = $getContext(Field, undefined); const state = field ? $store(field.state) : undefined;`, with `const` and no other test (BRM197). When a constant default exists, give a store as the fallback: `const locale = $store($getContext(LocaleContext, store('en-US')))`. The store is made for each reader, only without a provider. The variable follows the store. With `let`, a write such as `x = next` or `x++` calls `set`, and a store without `set` throws a `TypeError` when the variable registers. On resume the browser runs a source that is not a context once, with the values the server sent (a signal changed before the reader's code loads is not seen), and a store it makes starts from its first value. A store in a prop, a script value or a context must come from `brumate/store`, or be a store of another library wrapped with `bridge()`, or the server render throws. A source that awaits is an error (BRM198).
|
|
@@ -36,10 +36,31 @@
|
|
|
36
36
|
- The start value of a signal is computed once, on the server, and does not track what it reads. Use a memo for a value that follows others.
|
|
37
37
|
- Without an argument, `$signal<number>()` starts as `undefined`.
|
|
38
38
|
- `$produce(signal, (draft) => …)` changes a draft in place and writes the result as a new value. Without it, assign a new array or object: `todos = todos.map(…)`.
|
|
39
|
+
- `$produce` drafts plain objects, arrays, `Map`s and `Set`s, also inside the value. A map or set is copied on the first change and keeps the order of its entries. Keys of a map are never drafted: use the key of the base value, as `draft.set(id, value)` does. An instance of another class is used as it is: return a new value instead.
|
|
39
40
|
- `$untrack(expression)` reads without depending on the values in it.
|
|
40
41
|
- A signal or a memo holds data that the server can send: strings, numbers, booleans, `null`, `undefined`, `bigint`, plain objects and arrays, `Date`, `Map`, `Set`, `URL`, typed arrays and promises. It never holds a function, a class instance or a regular expression. Keep a function as a plain function in the script, or pass it as a function prop. Send the source and the flags of a regular expression, and make it where you use it. An app that sends a class registers a plugin in `src/serial.ts`.
|
|
41
42
|
- Declare signals and memos at the top level of a script, or of the script of a block. A signal never leaves its file: pass its value, or a function that writes it.
|
|
42
43
|
|
|
44
|
+
```brm
|
|
45
|
+
<script>
|
|
46
|
+
import { $produce, $signal } from 'brumate/signals';
|
|
47
|
+
|
|
48
|
+
let votes = $signal(new Map([['ada', 0]]));
|
|
49
|
+
let voters = $signal(new Set<string>());
|
|
50
|
+
|
|
51
|
+
function vote(name: string) {
|
|
52
|
+
$produce(votes, (draft) => {
|
|
53
|
+
draft.set(name, (draft.get(name) ?? 0) + 1);
|
|
54
|
+
});
|
|
55
|
+
$produce(voters, (draft) => {
|
|
56
|
+
draft.add(name);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<button onClick=(() => vote('ada'))>Ada: {votes.get('ada')}, {voters.size} voters</button>
|
|
62
|
+
```
|
|
63
|
+
|
|
43
64
|
```brm wrong: Cannot assign to memo "double"
|
|
44
65
|
<script>
|
|
45
66
|
import { $memo, $signal } from 'brumate/signals';
|
|
@@ -76,6 +97,22 @@
|
|
|
76
97
|
<p>{count}</p>
|
|
77
98
|
```
|
|
78
99
|
|
|
100
|
+
A signal has the type of its start value. `brumate check` and `brumate-tsc` report a write of another type:
|
|
101
|
+
|
|
102
|
+
```brm type-error: TS2322
|
|
103
|
+
<script>
|
|
104
|
+
import { $signal } from 'brumate/signals';
|
|
105
|
+
|
|
106
|
+
let count = $signal(0);
|
|
107
|
+
|
|
108
|
+
function reset() {
|
|
109
|
+
count = 'zero';
|
|
110
|
+
}
|
|
111
|
+
</script>
|
|
112
|
+
|
|
113
|
+
<button onClick=reset>{count}</button>
|
|
114
|
+
```
|
|
115
|
+
|
|
79
116
|
## Other derived values
|
|
80
117
|
|
|
81
118
|
- `const query = $gate(input, (_, next) => next.length >= 2)` takes a new value only when the guard returns true, and the readers do not run otherwise. The first value passes.
|
|
@@ -191,10 +228,10 @@ A memo can hold a promise, such as the result of a server function. Markup and o
|
|
|
191
228
|
- `$client(callback, trigger)` runs once. The trigger is `'visible'` (the default), `'idle'` or `'load'`. Prefer `'visible'` or `'idle'`.
|
|
192
229
|
- A callback returns a cleanup function if it needs one. It runs before the next run of an effect, and when the component leaves the page.
|
|
193
230
|
- An effect depends on the values read by the functions that it calls. Wrap a call that reads and writes the same signal in `$untrack(save())`.
|
|
194
|
-
- The callback of `$effect` and `$client` takes no parameters
|
|
231
|
+
- The callback of `$effect` and `$client` takes no parameters. It can be `async`, as below.
|
|
195
232
|
- `ref=$bind(name)` writes the element into the signal `name`. On the server it is `undefined`, so read it in handlers, effects and `$client` callbacks.
|
|
196
233
|
- A handler that only writes signals needs no effect: the page updates by itself.
|
|
197
|
-
- An effect that only sets a signal from other signals should be a `$memo`, or a write in the handler that changes them. Keep `$effect` for work outside the page's state: element methods, cookies, `document.title`, timers and libraries.
|
|
234
|
+
- An effect that only sets a signal from other signals should be a `$memo`, or a write in the handler that changes them. Keep `$effect` for work outside the page's state: element methods, cookies, `document.title`, timers and libraries. The compiler warns about such an effect with BRM209, `"message" is written only by this effect. Use …`, and gives the memo when the effect has one assignment and no `if`.
|
|
198
235
|
|
|
199
236
|
```brm wrong: The trigger of $client must be "visible", "idle" or "load"
|
|
200
237
|
<script>
|
|
@@ -218,9 +255,47 @@ A memo can hold a promise, such as the result of a server function. Markup and o
|
|
|
218
255
|
<input ref=$bind(field)>
|
|
219
256
|
```
|
|
220
257
|
|
|
258
|
+
### Async effects
|
|
259
|
+
|
|
260
|
+
```ts module="chat.ts"
|
|
261
|
+
export async function connect(room: string): Promise<{ room: string; close(): Promise<void> }> {
|
|
262
|
+
return { room, close: async () => {} };
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
```brm uses
|
|
267
|
+
<script>
|
|
268
|
+
import { $effect, $signal } from 'brumate/signals';
|
|
269
|
+
import { connect } from './chat.ts';
|
|
270
|
+
|
|
271
|
+
let room = $signal('general');
|
|
272
|
+
|
|
273
|
+
$effect(async () => {
|
|
274
|
+
const connection = await connect(room);
|
|
275
|
+
return async () => await connection.close();
|
|
276
|
+
});
|
|
277
|
+
</script>
|
|
278
|
+
|
|
279
|
+
<button onClick=(() => (room = 'random'))>Join random</button>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
- The callback of `$effect` and `$client` can be `async`, as `$client(async () => { … }, 'idle')`. A run that goes stale while it is pending cleans up as soon as it settles, so it needs no flag.
|
|
283
|
+
- One run at a time: the next run starts after the run before it and its cleanup have settled. Here `connection` is closed before the next `connect`. A scope that goes, such as a closed `#if`, calls the cleanup and does not wait for a pending run.
|
|
284
|
+
- The cleanup is a function, an async function, or an object with `[Symbol.dispose]` or `[Symbol.asyncDispose]`, such as a `DisposableStack`. A sync effect takes the same forms.
|
|
285
|
+
- Reads after an `await` are dependencies, as before it. A write after an `await` makes its own update, as in an async handler.
|
|
286
|
+
- An effect that needs the value of a memo that has none yet waits with `await $resolve(memo)`. A read of that memo before the first `await` skips the run. A read after an `await` that finds no value throws to the nearest `#try`.
|
|
287
|
+
- A rejection of the run or of its cleanup goes to the nearest `#try`.
|
|
288
|
+
|
|
221
289
|
## Context
|
|
222
290
|
|
|
223
|
-
```
|
|
291
|
+
```ts module="theme.ts"
|
|
292
|
+
import { createContext } from 'brumate/context';
|
|
293
|
+
|
|
294
|
+
export const Theme: ReturnType<typeof createContext<'light' | 'dark'>> =
|
|
295
|
+
createContext<'light' | 'dark'>('theme');
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
```brm uses
|
|
224
299
|
<script>
|
|
225
300
|
import { $getContext, $setContext, $signal } from 'brumate/signals';
|
|
226
301
|
import { Theme } from './theme.ts';
|
|
@@ -233,7 +308,7 @@ A memo can hold a promise, such as the result of a server function. Markup and o
|
|
|
233
308
|
<p>{parent}</p>
|
|
234
309
|
```
|
|
235
310
|
|
|
236
|
-
`createContext` comes from `brumate/context
|
|
311
|
+
`createContext` comes from `brumate/context` and is called in a `.ts` file, as `theme.ts` above shows. It takes only a key and has no default. A component reads the context of the nearest component above it, children included, and `$getContext` throws when none provides it. Give a fallback for a read that may have no provider: `$getContext(Theme, 'light')`.
|
|
237
312
|
|
|
238
313
|
## Derived stores
|
|
239
314
|
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
|
|
25
25
|
- `<script>` runs once for each instance, on the server. `<script module>` runs once per module, and its exports can be imported.
|
|
26
26
|
- `<style>` is scoped to the component. `<style global>` is not: its rules apply to the whole page, such as `body` or `.toolbar button`, with no `:global(…)` around them. `lang="scss"` and `lang="less"` work in both. Both are allowed at the top level of the file and of a block body.
|
|
27
|
-
-
|
|
27
|
+
- Scoping adds no specificity. The scope is `:where([b-c-<hash>])`, so `.a .b` keeps (0,2,0), and a global or parent rule of the same specificity that comes later in the page overrides it.
|
|
28
|
+
- In a build, the server writes the CSS of the components that a page renders into the page as `<style>` elements, so the first paint needs no request. The `.css` files of the bundles hold the same CSS for the rest of the visit, and are cached across pages.
|
|
29
|
+
- A file has at most one `<script>` and one `<script module>`. Markup can come before or after them. `<script inline>` and `<script src>` are markup (see below).
|
|
28
30
|
- Markup in a script, an expression or an attribute value is an error. Use a `#template`.
|
|
29
31
|
|
|
30
32
|
## Expressions and attributes
|
|
@@ -164,6 +166,7 @@ A file uses another component by importing it, and renders it with a capitalized
|
|
|
164
166
|
<p>{people[0].name}</p>
|
|
165
167
|
} #catch (error, reset) {
|
|
166
168
|
<p>{String(error)}</p>
|
|
169
|
+
<button onClick=reset>Retry</button>
|
|
167
170
|
}
|
|
168
171
|
|
|
169
172
|
#portal {
|
|
@@ -218,22 +221,30 @@ A file uses another component by importing it, and renders it with a capitalized
|
|
|
218
221
|
- `$id()` gives an ID that is the same on the server and in the browser: `const field = $id();`, then `<label for=field>` and `<input id=field>`.
|
|
219
222
|
- `<script>` can export nothing. A value that other files import goes in `<script module>`.
|
|
220
223
|
- `#head { <title>{title}</title> <meta name="description" content="…"> }` sets the head of the page. A `<title>` outside `#head` is an error.
|
|
221
|
-
-
|
|
224
|
+
- `<script inline>` holds code of the file, as written: the compiler does not read it, so `<`, `{` and `}` stay. `<script src="…">` loads a file and has nothing inside. A client navigation does not run a head script again. Add `data-rerun` to one that must run after each navigation. The script gets the nonce of the page.
|
|
222
225
|
|
|
223
226
|
```brm
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
#head {
|
|
228
|
+
<script inline data-rerun>
|
|
229
|
+
document.documentElement.dataset.visits = String(Number(localStorage.visits || 0) + 1);
|
|
230
|
+
</script>
|
|
231
|
+
}
|
|
232
|
+
```
|
|
227
233
|
|
|
228
|
-
|
|
229
|
-
const attribute = nonce ? ` nonce="${nonce}"` : '';
|
|
230
|
-
</script>
|
|
234
|
+
- `trigger` says when a script loads: `idle`, `visible` (when the element after it comes into view, not in `#head`), `interaction` (the first `pointerdown`, `keydown`, `touchstart` or `scroll`) or `load`. Use it for scripts of other sites, such as analytics or a chat widget. It is a plain string, and does not go with `data-rerun`.
|
|
231
235
|
|
|
236
|
+
```brm
|
|
232
237
|
#head {
|
|
233
|
-
|
|
238
|
+
<script src="https://cdn.example.com/chat.js" trigger="idle"></script>
|
|
234
239
|
}
|
|
240
|
+
|
|
241
|
+
<script inline trigger="interaction">
|
|
242
|
+
window.dataLayer = window.dataLayer || [];
|
|
243
|
+
</script>
|
|
235
244
|
```
|
|
236
245
|
|
|
246
|
+
- A page runs a script once, by its resolved `src` or by the text of an inline script. With JS off, only the scripts of `#head` without a trigger run.
|
|
247
|
+
|
|
237
248
|
- A value that changes in a `<textarea>` or `<title>` must be its whole content: `<textarea>{text}</textarea>`.
|
|
238
249
|
|
|
239
250
|
## Modules of reactive logic
|
|
@@ -266,6 +277,44 @@ export function counter(start: number) {
|
|
|
266
277
|
- The function ends with `return { … }`, an object of plain keys, and returns nowhere else.
|
|
267
278
|
- A component calls it at the top level of its script, and destructures the result with plain names.
|
|
268
279
|
|
|
280
|
+
### Shared state at module level
|
|
281
|
+
|
|
282
|
+
`$signal` and `$memo` also work at the top level of a `.brm.ts` module. They give one value for the module, which every component that imports it reads like its own signal.
|
|
283
|
+
|
|
284
|
+
```ts module="cart.brm.ts"
|
|
285
|
+
import { $memo, $signal } from 'brumate/signals';
|
|
286
|
+
|
|
287
|
+
export let items: number[] = $signal<number[]>([]);
|
|
288
|
+
export const total: number = $memo(items.reduce((sum, price) => sum + price, 0));
|
|
289
|
+
|
|
290
|
+
export function add(price: number): void {
|
|
291
|
+
items = [...items, price];
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
```brm uses
|
|
296
|
+
<script>
|
|
297
|
+
import { add, items, total } from './cart.brm.ts';
|
|
298
|
+
</script>
|
|
299
|
+
|
|
300
|
+
<button onClick=(() => add(5))>Add</button>
|
|
301
|
+
<p>{items.length} items, {total}</p>
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
```brm wrong: Cannot assign to module signal "items". Export a function from ./cart.brm.ts that writes it, and call that function
|
|
305
|
+
<script>
|
|
306
|
+
import { items } from './cart.brm.ts';
|
|
307
|
+
</script>
|
|
308
|
+
|
|
309
|
+
<button onClick=(() => (items = []))>Clear</button>
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
- A component cannot write what it imports. Write it in a function that the module exports, such as `add`. The same forms work in `<script module>`, and the component writes a signal of its own `<script module>` in its script.
|
|
313
|
+
- `$effect`, `$client` and the other compile-time functions cannot run at the top level of a module, nor can a destructuring write such as `[count] = values` (BRM211). Put them in a component, or in a module function.
|
|
314
|
+
- A module memo can load, as `$memo(await fetchUser(id))`: it loads once for every importer, for the latest values of its signals, and a component reads it as its own memo, with `#loading`, `$isPending` and `$resolve`. A gate or timed value of a module over it waits for it.
|
|
315
|
+
- A `.ts` file that imports a module signal gets its store, not its value (BRM208). Read the value in an exported function of the module.
|
|
316
|
+
- A module signal is one value for the whole server process, shared by every request. Keep per-request data in a context.
|
|
317
|
+
|
|
269
318
|
## Parts of @brumate/ui
|
|
270
319
|
|
|
271
320
|
The light, dark or system choice of the page is `ColorScheme` of `@brumate/ui`. It keeps the choice in a cookie, so the server renders the first response with it. `colorScheme()` reads and changes it from a component inside, at the top level of its script.
|