brumate 0.6.1 → 0.7.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.
Files changed (90) hide show
  1. package/check.d.ts +3 -3
  2. package/dist/{boot-DkbcqdUz.d.ts → boot-Cs_P8cDu.d.ts} +2 -2
  3. package/dist/cli.js +77 -6
  4. package/dist/cli.js.map +1 -1
  5. package/dist/{client-CqGDbWd_.d.ts → client-BDPsTd4q.d.ts} +40 -14
  6. package/dist/{client-C3vRNuLi.js → client-DYIZ7BYK.js} +271 -112
  7. package/dist/client-DYIZ7BYK.js.map +1 -0
  8. package/dist/{client-routes-BtGpYCef.js → client-routes-BmPvNr4s.js} +10 -1
  9. package/dist/client-routes-BmPvNr4s.js.map +1 -0
  10. package/dist/{context-btHuB01Z.d.ts → context-BNgBXVUQ.d.ts} +7 -5
  11. package/dist/{context-CTiSzQRc.js → context-CU4Fpn5a.js} +10 -13
  12. package/dist/context-CU4Fpn5a.js.map +1 -0
  13. package/dist/{defer-M18UKyfG.js → defer-7JDhFxQq.js} +2 -2
  14. package/dist/{defer-M18UKyfG.js.map → defer-7JDhFxQq.js.map} +1 -1
  15. package/dist/{devtools-YnvrZ6D8.js → devtools-CzSp1GGq.js} +34 -24
  16. package/dist/devtools-CzSp1GGq.js.map +1 -0
  17. package/dist/{devtools-panel-DRcKclEG.js → devtools-panel-DugGrz7L.js} +32 -9
  18. package/dist/devtools-panel-DugGrz7L.js.map +1 -0
  19. package/dist/{features-CbgII-o7.js → features-DwMYKBIC.js} +6 -2
  20. package/dist/features-DwMYKBIC.js.map +1 -0
  21. package/dist/{files-HzPDUyTY.js → files-XX5yW3KL.js} +94 -3
  22. package/dist/files-XX5yW3KL.js.map +1 -0
  23. package/dist/index.d.ts +49 -0
  24. package/dist/index.js +3 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/{inspect-Q5W0A66e.js → inspect-B9cRF6AM.js} +2767 -2077
  27. package/dist/inspect-B9cRF6AM.js.map +1 -0
  28. package/dist/{loader-C-S3yzep.js → loader-BGSXt_Eb.js} +5 -5
  29. package/dist/{loader-C-S3yzep.js.map → loader-BGSXt_Eb.js.map} +1 -1
  30. package/dist/{rpc-C_znDZ_w.js → rpc-B9EkaPdU.js} +3 -3
  31. package/dist/{rpc-C_znDZ_w.js.map → rpc-B9EkaPdU.js.map} +1 -1
  32. package/dist/runtime/bundles.d.ts +1 -1
  33. package/dist/runtime/bundles.js +2 -0
  34. package/dist/runtime/bundles.js.map +1 -1
  35. package/dist/runtime/client.d.ts +4 -4
  36. package/dist/runtime/client.js +4 -4
  37. package/dist/runtime/context.d.ts +2 -2
  38. package/dist/runtime/context.js +1 -1
  39. package/dist/runtime/devtools.d.ts +15 -2
  40. package/dist/runtime/devtools.js +2 -2
  41. package/dist/runtime/hot.d.ts +1 -1
  42. package/dist/runtime/html.d.ts +1 -1
  43. package/dist/runtime/loader.d.ts +2 -2
  44. package/dist/runtime/loader.js +2 -2
  45. package/dist/runtime/server.d.ts +4 -4
  46. package/dist/runtime/server.js +4 -4
  47. package/dist/runtime/signals.d.ts +2 -2
  48. package/dist/runtime/signals.js +43 -5
  49. package/dist/runtime/signals.js.map +1 -1
  50. package/dist/runtime/static-loader.d.ts +2 -2
  51. package/dist/runtime/static-loader.js +1 -1
  52. package/dist/runtime/store.d.ts +2 -0
  53. package/dist/runtime/store.js +1 -0
  54. package/dist/runtime/testing.d.ts +2 -2
  55. package/dist/runtime/testing.js +2 -2
  56. package/dist/{search-params-CM1RWR2P.js → search-params-Cy3uRphR.js} +33 -8
  57. package/dist/search-params-Cy3uRphR.js.map +1 -0
  58. package/dist/{server-BcT9icQ4.js → server-C1OTFH4r.js} +127 -14
  59. package/dist/server-C1OTFH4r.js.map +1 -0
  60. package/dist/{server-dP_ucRiJ.d.ts → server-CavhuoFI.d.ts} +32 -8
  61. package/dist/{shared-CzbnWkVA.d.ts → shared-CRduzyi3.d.ts} +15 -2
  62. package/dist/{signals-BwD4u22K.d.ts → signals-DBnq9QRW.d.ts} +46 -6
  63. package/dist/{static-loader-DysAET-w.d.ts → static-loader-D5hvLQK7.d.ts} +2 -2
  64. package/dist/{static-loader-Bt2WDkY1.js → static-loader-XGXMzfJR.js} +3 -3
  65. package/dist/{static-loader-Bt2WDkY1.js.map → static-loader-XGXMzfJR.js.map} +1 -1
  66. package/dist/store-BIBAYZo-.js +293 -0
  67. package/dist/store-BIBAYZo-.js.map +1 -0
  68. package/dist/store-xlTzAM_r.d.ts +171 -0
  69. package/dist/{stream-DRjx0keF.js → stream-BBnArf_5.js} +89 -3
  70. package/dist/stream-BBnArf_5.js.map +1 -0
  71. package/dist/vite.d.ts +1 -1
  72. package/dist/vite.js +128 -13
  73. package/dist/vite.js.map +1 -1
  74. package/elements.d.ts +268 -21
  75. package/package.json +5 -1
  76. package/skills/brumate/SKILL.md +1 -1
  77. package/skills/brumate/references/errors.md +127 -9
  78. package/skills/brumate/references/signals.md +37 -30
  79. package/skills/brumate/references/state.md +3 -2
  80. package/dist/client-C3vRNuLi.js.map +0 -1
  81. package/dist/client-routes-BtGpYCef.js.map +0 -1
  82. package/dist/context-CTiSzQRc.js.map +0 -1
  83. package/dist/devtools-YnvrZ6D8.js.map +0 -1
  84. package/dist/devtools-panel-DRcKclEG.js.map +0 -1
  85. package/dist/features-CbgII-o7.js.map +0 -1
  86. package/dist/files-HzPDUyTY.js.map +0 -1
  87. package/dist/inspect-Q5W0A66e.js.map +0 -1
  88. package/dist/search-params-CM1RWR2P.js.map +0 -1
  89. package/dist/server-BcT9icQ4.js.map +0 -1
  90. package/dist/stream-DRjx0keF.js.map +0 -1
@@ -4,41 +4,45 @@ The compiler replaces each call and removes the import, so none of them ship. Im
4
4
 
5
5
  "Top level of a script" means a statement of the component's `<script>`, or of a `<script>` at the start of a block body. It is not inside a function or another statement.
6
6
 
7
- | Function | Returns | Where |
8
- | ------------------------------ | -------------------------- | ----------------------------------------------------- |
9
- | `$props<T>()` | `T` | `const` or `let` in the component script |
10
- | `$signal<T>(value?)` | `T` | `let` at the top level of a script |
11
- | `$memo<T>(value)` | the value, never a promise | `const` at the top level of a script |
12
- | `$debounced(value, ms)` | the value, as a memo | `const` at the top level of a script |
13
- | `$throttled(value, ms)` | the value, as a memo | `const` at the top level of a script |
14
- | `$isPending(memo)` | `boolean` | Any expression |
15
- | `$resolve(memo, options?)` | `Promise<T>` | A handler, an effect or a `$client` callback |
16
- | `$isPassed(prop)` | `boolean` | `const` in the component script |
17
- | `$isBound(prop)` | `boolean` | Any expression |
18
- | `$effect(callback)` | `void` | Statement at the top level of a script |
19
- | `$client(callback, trigger?)` | `void` | Statement at the top level of a script |
20
- | `$untrack(value)` | the value | Any expression |
21
- | `$produce(signal, recipe)` | `void` | Where a signal can be written |
22
- | `$setContext(context, value)` | `void` | Statement at the top level of a script |
23
- | `$getContext(context)` | the value | `const` at the top level of a script |
24
- | `$route(path?)` | `{ url, search, params }` | `const` at the top level of a script |
25
- | `$searchParam(name, options?)` | the value of the parameter | `let` at the top level of a script |
26
- | `$navigation()` | `{ pending, from, to }` | `const` at the top level of a script |
27
- | `$id()` | `string` | `const` at the top level of a script |
28
- | `$title(value)` | `void` | Statement at the top level of a script |
29
- | `$action(fn)` | the result, or `undefined` | `const` at the top level of a script |
30
- | `$optimistic(source)` | the value of `source` | `let` at the top level of a script |
31
- | `$handler(fn, ...args)` | a handler | Any expression of a script or a module function |
32
- | `$bind(value, set?)` | a binding | The whole value of a prop, or of `value` or `checked` |
7
+ | Function | Returns | Where |
8
+ | --------------------------------- | -------------------------- | ----------------------------------------------------- |
9
+ | `$props<T>()` | `T` | `const` or `let` in the component script |
10
+ | `$signal<T>(value?)` | `T` | `let` at the top level of a script |
11
+ | `$memo<T>(value)` | the value, never a promise | `const` at the top level of a script |
12
+ | `$gate(value, guard)` | the value, as a memo | `const` at the top level of a script |
13
+ | `$debounced(value, ms)` | the value, as a memo | `const` at the top level of a script |
14
+ | `$throttled(value, ms)` | the value, as a memo | `const` at the top level of a script |
15
+ | `$isPending(...memos)` | `boolean` | Any expression |
16
+ | `$resolve(memo, options?)` | `Promise<T>` | A handler, an effect or a `$client` callback |
17
+ | `$isPassed(prop)` | `boolean` | `const` in the component script |
18
+ | `$isBound(prop)` | `boolean` | Any expression |
19
+ | `$effect(callback)` | `void` | Statement at the top level of a script |
20
+ | `$client(callback, trigger?)` | `void` | Statement at the top level of a script |
21
+ | `$untrack(value)` | the value | Any expression |
22
+ | `$produce(signal, recipe)` | `void` | Where a signal can be written |
23
+ | `$setContext(context, value)` | `void` | Statement at the top level of a script |
24
+ | `$getContext(context, fallback?)` | the value, or the fallback | `const` at the top level of a script |
25
+ | `$store(source)` | the value of the store | `const` or `let` at the top level of a script |
26
+ | `$toStore(value)` | a store | A value of `$setContext` |
27
+ | `$route(path?)` | `{ url, search, params }` | `const` at the top level of a script |
28
+ | `$searchParam(name, options?)` | the value of the parameter | `let` at the top level of a script |
29
+ | `$navigation()` | `{ pending, from, to }` | `const` at the top level of a script |
30
+ | `$id()` | `string` | `const` at the top level of a script |
31
+ | `$title(value)` | `void` | Statement at the top level of a script |
32
+ | `$action(fn)` | the result, or `undefined` | `const` at the top level of a script |
33
+ | `$optimistic(source)` | the value of `source` | `let` at the top level of a script |
34
+ | `$handler(fn, ...args)` | a handler | Any expression of a script or a module function |
35
+ | `$bind(value, set?)` | a binding | The whole value of a prop, or of `value` or `checked` |
33
36
 
34
37
  ## What each one does
35
38
 
36
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.
37
40
  - `$signal(value)`: writable state. Read it and assign to it as a variable. The start value is computed once, on the server.
38
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
+ - `$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.
39
43
  - `$debounced(value, ms)`: a memo that takes the value once it stops changing for `ms` milliseconds. `ms` is a number literal.
40
44
  - `$throttled(value, ms)`: a memo that takes the value at most once every `ms` milliseconds.
41
- - `$isPending(memo)`: true while a new value of the memo loads in the browser. Always false on the server.
45
+ - `$isPending(...memos)`: true while a new value of any of the memos loads in the browser. Always false on the server.
42
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).
43
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.
44
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`.
@@ -46,8 +50,11 @@ The compiler replaces each call and removes the import, so none of them ship. Im
46
50
  - `$client(callback, trigger?)`: runs the callback in the browser once. The trigger is `'visible'` (default), `'idle'` or `'load'`. It can return a cleanup function.
47
51
  - `$untrack(value)`: reads a value, or calls a function, without depending on it.
48
52
  - `$produce(signal, recipe)`: changes a draft of an object or array in a signal, and writes the result as a new value. The recipe can return a new value instead.
49
- - `$setContext(context, value)`: gives a value of a context to the components inside. Create the context with `createContext` from `brumate/context`.
50
- - `$getContext(context)`: reads a context from the nearest component above that provides it, or its default.
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
+ - `$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
+ - `$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).
56
+ - `$toStore(value)`: a store for a value of `$setContext`, from a memo, a signal or a prop, alone or as a key of an object. A store of a signal has a `set` that writes the signal. Every context is static, and its readers update through the stores it holds. Make a store of your own with `store(value)` from `brumate/store`.
57
+ - `bridge({ create, get, subscribe, set? })` from `brumate/store`: wraps a store of another library (zustand and the like) so it can cross the page state in a context or a prop. Keep its value in a module-level export of a script file or of `<script module>`, as `export const bearStore = bridge({ … })`, or the compiler reports BRM200. `create(snapshot)` makes the library's store: once for each call on the server, once in the browser at the first subscriber, with the data that `get(source)` gave on the server. `get` must give plain data the page can send. A provider calls `$setContext(BearContext, bearStore({ bears: 0 }))`, a reader binds `$store($getContext(BearContext))` and calls the library through `.source`, which is `undefined` in the browser until the store has a subscriber and its module has loaded (write `bear.source?.…`). Resume never calls `set`.
51
58
  - `$route(path?)`: the current route, as `{ url, search, params }`. The path is the route, such as `'/posts/[id]'`, and takes at most one argument.
52
59
  - `$searchParam(name, options?)`: a signal bound to one parameter of the query string. The server reads the URL, and a write in the browser changes it with `replaceState` (`{ history: 'push' }` for `pushState`) and asks the server nothing. Back and forward write the signal. Options: `default` (left out of the URL), `parse`, `serialize`, `history`, `server` (a write navigates). The name is a string literal.
53
60
  - `$navigation()`: the state of a navigation, as `{ pending, from, to }`. It takes no arguments.
@@ -60,4 +67,4 @@ The compiler replaces each call and removes the import, so none of them ship. Im
60
67
 
61
68
  ## Not supported
62
69
 
63
- Calling one of these is a compile error that names the replacement: `$ref` (use a `$signal` with `ref=$bind(name)`), `$watch` (use `$effect`), `$settled` (use `$client`), `$cleanup` (return a function from `$effect` or `$client`), `$store` (assign a new value to a `$signal`, or use `$produce`), `$get` and `$set` (signals cannot leave the file).
70
+ Calling one of these is a compile error that names the replacement: `$ref` (use a `$signal` with `ref=$bind(name)`), `$watch` (use `$effect`), `$settled` (use `$client`), `$cleanup` (return a function from `$effect` or `$client`), `$get` and `$set` (signals cannot leave the file), `$hasContext` (read with `$getContext(context, undefined)`, BRM197).
@@ -78,8 +78,9 @@
78
78
 
79
79
  ## Other derived values
80
80
 
81
+ - `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.
81
82
  - `const settled = $debounced(query, 300)` takes the value once it stops changing for 300 ms. `$throttled(value, ms)` takes it at most once in `ms`. The wait is a number literal.
82
- - `$isPending(memo)` is true while an async memo loads.
83
+ - `$isPending(memo)` is true while an async memo loads. `$isPending(a, b)` is true while any of them loads.
83
84
  - `let shown = $optimistic(source)` follows a memo, an action or a prop, and takes a value in the meantime.
84
85
  - `const field = $id()` is an ID that is the same on the server and in the browser.
85
86
 
@@ -232,4 +233,4 @@ A memo can hold a promise, such as the result of a server function. Markup and o
232
233
  <p>{parent}</p>
233
234
  ```
234
235
 
235
- `createContext` comes from `brumate/context`: `export const Theme = createContext<'light' | 'dark'>('light');` in a `.ts` file. A component reads the context of the nearest component above it, children included.
236
+ `createContext` comes from `brumate/context`: `export const Theme = createContext<'light' | 'dark'>('theme');` in a `.ts` file. 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')`.