@wcstack/state 4.0.0-rc.7 → 4.0.0-rc.9
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.ja.md +29 -34
- package/README.md +29 -34
- package/dist/auto.min.js +2 -1
- package/dist/auto.min.js.map +1 -0
- package/dist/index.esm.js +2 -1
- package/dist/index.esm.js.map +1 -0
- package/dist/split/auto.js +2 -1
- package/dist/split/auto.js.map +1 -0
- package/dist/split/chunks/{chunk-V34ZHCK5.js → chunk-4NJBYXIT.js} +2 -1
- package/dist/split/chunks/chunk-4NJBYXIT.js.map +1 -0
- package/dist/split/chunks/{chunk-JMPQHCIT.js → chunk-55J45X6H.js} +2 -1
- package/dist/split/chunks/chunk-55J45X6H.js.map +1 -0
- package/dist/split/chunks/{chunk-LTBR3OV5.js → chunk-7AYOQHZH.js} +2 -1
- package/dist/split/chunks/chunk-7AYOQHZH.js.map +1 -0
- package/dist/split/chunks/chunk-EIMTT5I3.js +2 -0
- package/dist/split/chunks/chunk-EIMTT5I3.js.map +1 -0
- package/dist/split/chunks/chunk-L3PFEJP7.js +2 -0
- package/dist/split/chunks/chunk-L3PFEJP7.js.map +1 -0
- package/dist/split/chunks/{chunk-W5KT4PQ3.js → chunk-M5SODAAE.js} +2 -1
- package/dist/split/chunks/chunk-M5SODAAE.js.map +1 -0
- package/dist/split/chunks/{chunk-SPWZUBQS.js → chunk-NOPTR2L3.js} +2 -1
- package/dist/split/chunks/chunk-NOPTR2L3.js.map +1 -0
- package/dist/split/chunks/chunk-SAUVGHSB.js +2 -0
- package/dist/split/chunks/chunk-SAUVGHSB.js.map +1 -0
- package/dist/split/chunks/{chunk-ARPZVNKL.js → chunk-UD3AYVP2.js} +2 -1
- package/dist/split/chunks/chunk-UD3AYVP2.js.map +1 -0
- package/dist/split/chunks/{chunk-XF6V6DWR.js → chunk-W4KOY6GT.js} +2 -1
- package/dist/split/chunks/chunk-W4KOY6GT.js.map +1 -0
- package/dist/split/chunks/{chunk-2EGTC36Y.js → chunk-ZN52NEIB.js} +2 -1
- package/dist/split/chunks/chunk-ZN52NEIB.js.map +1 -0
- package/dist/split/core.js +2 -1
- package/dist/split/core.js.map +1 -0
- package/dist/split/features/devtools.js +2 -1
- package/dist/split/features/devtools.js.map +1 -0
- package/dist/split/features/diagnostics.js +2 -1
- package/dist/split/features/diagnostics.js.map +1 -0
- package/dist/split/features/formats.js +2 -1
- package/dist/split/features/formats.js.map +1 -0
- package/dist/split/features/list-keys.js +2 -1
- package/dist/split/features/list-keys.js.map +1 -0
- package/dist/split/features/native-commands.js +2 -1
- package/dist/split/features/native-commands.js.map +1 -0
- package/dist/split/features/recursion.js +2 -1
- package/dist/split/features/recursion.js.map +1 -0
- package/dist/split/features/scopes.js +2 -1
- package/dist/split/features/scopes.js.map +1 -0
- package/dist/split/features/ssr.js +2 -1
- package/dist/split/features/ssr.js.map +1 -0
- package/dist/split/features/temporal.js +2 -1
- package/dist/split/features/temporal.js.map +1 -0
- package/package.json +1 -1
- package/dist/split/chunks/chunk-27N3IPIZ.js +0 -1
- package/dist/split/chunks/chunk-7EWPQMA6.js +0 -1
- package/dist/split/chunks/chunk-ALVA5TQM.js +0 -1
package/README.ja.md
CHANGED
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
| **getter が動く条件** | getter は遅延評価。評価需要は live binding・`$watch`・`$stream` の `args` の 3 箇所からしか生まれない | [評価のきっかけ](#評価のきっかけdemand-root) |
|
|
139
139
|
| **モジュール化** | `mount=` がモジュールを 1 本のツリーに接ぎ木し、`state: path` が部分木をコンポーネントにマウントする。個別対応付けは単一キーを繋ぎ、マウントされたコンポーネントの getter はマウント点で公開される | [ボリューム](#追加の状態をマウントするmount) · [丸ごとマウント](#丸ごとマウントstate-path) |
|
|
140
140
|
| **コンポーネント** | 排他的な 2 方式 — JavaScript クラス+`bind-component` か、HTML だけの DCC か | [機構の選び方](#コンポーネント機構の選び方) |
|
|
141
|
-
| **他要素との配線** | wc-bindable プロトコル、spread(`...: obj`)、`#init=` / `#sync=` の authority
|
|
141
|
+
| **他要素との配線** | wc-bindable プロトコル、spread(`...: obj`)、`#init=` / `#sync=` の authority、settable な入力 | [バインディング authority](#バインディング-authority-init--sync) · [Spread](#spread-バインディング-) · [Inputs](#inputs-と-attribute-ヒント) |
|
|
142
142
|
| **トークン** | command token が state から要素のメソッドを呼び、event token が要素のイベントを state へ戻す | [Command token](#command-tokenメソッドバインディング) · [Event token](#event-tokenイベントバインディング) |
|
|
143
143
|
| **時間** | `$stream` が非同期ソースを fold し、`$watch` が headless に反応する | [時間を扱う機構の選び方](#時間を扱う機構の選び方) |
|
|
144
144
|
| **初期化とライフサイクル** | state の供給は 6 通り。`$connectedCallback` 〜 `$stateReadyCallback`、`bootstrapState()` / `createState()` | [状態の初期化](#状態の初期化) · [ライフサイクルフック](#ライフサイクルフック) · [API リファレンス](#api-リファレンス) |
|
|
@@ -191,9 +191,9 @@
|
|
|
191
191
|
<script type="importmap">
|
|
192
192
|
{
|
|
193
193
|
"imports": {
|
|
194
|
-
"@wcstack/state/core": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.
|
|
195
|
-
"@wcstack/state/features/temporal": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.
|
|
196
|
-
"@wcstack/state/features/scopes": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.
|
|
194
|
+
"@wcstack/state/core": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.9/dist/split/core.js",
|
|
195
|
+
"@wcstack/state/features/temporal": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.9/dist/split/features/temporal.js",
|
|
196
|
+
"@wcstack/state/features/scopes": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.9/dist/split/features/scopes.js"
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
</script>
|
|
@@ -253,7 +253,7 @@
|
|
|
253
253
|
ページが名指したアドオンを、同じビルドから読み込みます。
|
|
254
254
|
|
|
255
255
|
```html
|
|
256
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.
|
|
256
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.9/dist/split/auto.js"></script>
|
|
257
257
|
<wcs-state features="scopes diagnostics">
|
|
258
258
|
<script type="module">
|
|
259
259
|
export default {
|
|
@@ -739,7 +739,7 @@ export default {
|
|
|
739
739
|
<wcs-fetch data-wcs="...: usersFetch; status: alternateStatus"></wcs-fetch>
|
|
740
740
|
```
|
|
741
741
|
|
|
742
|
-
**`undefined` は「無意見」** — 展開された state パスが `undefined` に解決される場合(slot オブジェクトでその input を初期化していない場合など)、プロパティ書き込みは**スキップ**され、要素側の既定値がそのまま生きます。実際に使うパスだけ初期化すれば十分で、`<wcs-fetch>` が `method` / `manual` / `body` を宣言していても `usersFetch: { value: null, loading: false }` だけで動きます。明示的にクリアしたい場合は `null` を代入してください(`null` は常に書き込まれます)。(このスキップは spread に限らず、要素の input
|
|
742
|
+
**`undefined` は「無意見」** — 展開された state パスが `undefined` に解決される場合(slot オブジェクトでその input を初期化していない場合など)、プロパティ書き込みは**スキップ**され、要素側の既定値がそのまま生きます。実際に使うパスだけ初期化すれば十分で、`<wcs-fetch>` が `method` / `manual` / `body` を宣言していても `usersFetch: { value: null, loading: false }` だけで動きます。明示的にクリアしたい場合は `null` を代入してください(`null` は常に書き込まれます)。(このスキップは spread に限らず、要素の input に値を渡すすべてのプロパティバインディングに適用されます。前にそのパスが値を持っていても同じで、要素には状態が最後に書いた値が残ります。これは wc-bindable の applier プロファイル(0.10.0 の A2)より厳しい規則で、A2 は値の後の `undefined` を書いて要素を初期状態に戻させます。状態はこのプロファイルを宣言しません。ほかの書き手 — React 19 や直接の代入 — は `undefined` を届けるので、wcstack の I/O ノードは `undefined` を「値が無い」として扱います。)**表示の表面は別です:** `textContent` / `innerText` / `innerHTML`・mustache やコメントバインディングのテキスト・`attr.*`・`style.*`・`class.*` には生かすべき要素側の既定値が無いので、`undefined` も `null` も「値が無い」— テキストは空になり、属性やスタイルは削除され、クラスは外れます。`class.*` だけは範囲が狭く、「値が無い」扱いになるのは `undefined` と `null` だけです — **それ以外の非 boolean は今も throw します**。クラスの束縛は真偽の切り替えなので、truthy な文字列は意図というより書き間違いである方がずっと多いためです。「truthy として扱う」つもりなら `class.on: flag|truthy` と書いてください。
|
|
743
743
|
|
|
744
744
|
**フィルタを挟んでも契約は保たれます。** 空値の判定はフィルタ**後**の値に対して行われるため、`String(value)` で結果を組み立てるフィルタは、値が無いときに `"undefined"` という**文字**を作ってしまいかねません。書式の族(`upper` / `lower` / `capitalize` / `trim` / `slice` / `padStart` / `padEnd` / `repeat` / `reverse` / `truncate` / `unit`)は代わりに `undefined` / `null` を素通しするので、`attr.title: x|trim` はフィルタの無い `attr.title: x` と同じく属性を消します。次の 3 群は**意図的に素通ししません**: 空値そのものが入力として意味を持つフィルタ(`defaults` / `coalesce` / `nullIfEmpty` / `boolean` / `truthy` / `falsy` / `not` / `eq` / `ne`)、変換が仕事のフィルタ(`int` / `float` / `number` / `string` — `undefined|string` は今も `"undefined"`)、値の型を検査するフィルタ(数値・日付・配列の族。`toFixed` / `date` / `join` など)。最後の群は throw しますが、それは束縛 1 本に閉じ込められ `$errorCallback` に報告されます。値が無いことが正当にありうるなら前に `coalesce` を置いてください(`price|coalesce(0)|toFixed(2)`)。
|
|
745
745
|
|
|
@@ -2600,11 +2600,11 @@ $renderedCallback(paths) {
|
|
|
2600
2600
|
- **マウントされた `bind-component` スコープでは実行されません** —— マウントされたコンポーネントの `$watch` 宣言は、ルート state へ誘導する `wcs/mount-dollar-declaration` の警告を 1 回出して無視されます。`$stream` と `$renderedCallback` も同様です。ボリュームは `$watch` を拒否します([`mount=`](#追加の状態をマウントするmount)): ルートにフルパス(`"cart.total"`)で宣言してください。plain な(配線なし Shadow の)子は独立ツリーを持つので宣言できます。
|
|
2601
2601
|
- **SSR では実行されません** —— ハンドラの副作用がサーバーとクライアントで二重に走るためです。
|
|
2602
2602
|
|
|
2603
|
-
## Inputs
|
|
2603
|
+
## Inputs と attribute ヒント
|
|
2604
2604
|
|
|
2605
|
-
`wcBindable.inputs`
|
|
2605
|
+
`wcBindable.inputs` は、状態が書いてよいメンバー(state → 要素)を宣言します。方向認識初期同期(既定 ON)の下では、メンバが **state から settable であること**を示すのが `inputs` です。settable なのに `properties` にしか宣言されていないメンバは output-only 扱いになり、state からの書き込みが抑止されます — [バインディング authority](#バインディング-authority-init--sync) を参照してください。
|
|
2606
2606
|
|
|
2607
|
-
`
|
|
2607
|
+
状態が書くのは入力の**プロパティ**だけです。エントリの省略できる `attribute` は、マークアップでそのプロパティに対応する HTML 属性の名前(`<my-chip label-text="…">`)です。wc-bindable プロトコルの定めるとおりツールのための宣言で、状態はこの属性を書きません(wc-bindable 0.10.0 の applier プロファイル A1: applier はプロパティを書き、ヒントの属性は書かない。要素が upgrade される前に属性へ逃げることもしない — 状態は定義を待ちます)。プロパティを属性に反映する(`attributeChangedCallback`・CSS の属性セレクタ・DevTools のため)のは要素の仕事で、setter の中で、要素だけが知っている書き方で行います(boolean は属性の有無、`"on"` / `"off"`、JSON など):
|
|
2608
2608
|
|
|
2609
2609
|
```javascript
|
|
2610
2610
|
class MyChip extends HTMLElement {
|
|
@@ -2612,41 +2612,28 @@ class MyChip extends HTMLElement {
|
|
|
2612
2612
|
protocol: "wc-bindable", version: 1,
|
|
2613
2613
|
properties: [],
|
|
2614
2614
|
inputs: [
|
|
2615
|
-
{ name: "
|
|
2616
|
-
{ name: "
|
|
2617
|
-
{ name: "
|
|
2615
|
+
{ name: "labelText", attribute: "label-text" }, // マークアップ: <my-chip label-text="…">
|
|
2616
|
+
{ name: "selected", attribute: "selected" }, // マークアップ: <my-chip selected>
|
|
2617
|
+
{ name: "data" }, // プロパティだけ
|
|
2618
2618
|
],
|
|
2619
2619
|
};
|
|
2620
|
+
get labelText() { return this.getAttribute("label-text") ?? ""; }
|
|
2621
|
+
set labelText(v) { v == null ? this.removeAttribute("label-text") : this.setAttribute("label-text", v); }
|
|
2622
|
+
get selected() { return this.hasAttribute("selected"); }
|
|
2623
|
+
set selected(v) { this.toggleAttribute("selected", Boolean(v)); }
|
|
2620
2624
|
}
|
|
2621
2625
|
```
|
|
2622
2626
|
|
|
2623
2627
|
```html
|
|
2624
|
-
<my-chip data-wcs="
|
|
2628
|
+
<my-chip data-wcs="labelText: chip.title; selected: chip.on; data: chip.payload"></my-chip>
|
|
2625
2629
|
```
|
|
2626
2630
|
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
```text
|
|
2630
|
-
chip.payload = { id: 1 } → element.data = { id: 1 } かつ setAttribute("data", '{"id":1}')
|
|
2631
|
-
chip.title = "新着" → element.labelText = "新着" かつ setAttribute("label-text", "新着")
|
|
2632
|
-
chip.payload = null → element.data = null かつ removeAttribute("data")
|
|
2633
|
-
```
|
|
2634
|
-
|
|
2635
|
-
属性値のエンコード:
|
|
2636
|
-
|
|
2637
|
-
| 値の型 | ミラーされる属性 |
|
|
2638
|
-
|---|---|
|
|
2639
|
-
| `string` / `number` / `bigint` | `String(value)` |
|
|
2640
|
-
| `true` | 空の属性(`""`) |
|
|
2641
|
-
| `false` / `null` / `undefined` | 属性を削除 |
|
|
2642
|
-
| `object` / `array` | `JSON.stringify(value)`(循環参照時は `String(value)` にフォールバック) |
|
|
2631
|
+
`chip.title = "新着"` は `element.labelText = "新着"` を書き、setter が `label-text` に反映します。`chip.on = false` は `element.selected = false` を書き、setter が `selected` を外します。
|
|
2643
2632
|
|
|
2644
2633
|
補足:
|
|
2645
2634
|
|
|
2646
|
-
-
|
|
2647
|
-
-
|
|
2648
|
-
- ミラーはベストエフォート: `setAttribute` の失敗は握りつぶされ、プロパティ書き込みをブロックしない
|
|
2649
|
-
- ネイティブ HTML 要素は `inputs` を完全に無視する —— ミラーは `static wcBindable` を公開するカスタム要素でのみ有効になる
|
|
2635
|
+
- 3.x はプロパティの後に属性にも書いていました(`String(value)`、オブジェクトは JSON)。setter で反映する要素は影響を受けません。setter を持たず、binder が属性を書くことに頼っていた要素には、setter が要ります(移行ガイド §3.4)。
|
|
2636
|
+
- ネイティブ HTML 要素は `inputs` を完全に無視します —— 宣言が効くのは `static wcBindable` を公開するカスタム要素だけです。
|
|
2650
2637
|
|
|
2651
2638
|
## コンポーネント機構の選び方
|
|
2652
2639
|
|
|
@@ -3538,7 +3525,15 @@ bootstrapState(config?, registry?)
|
|
|
3538
3525
|
|
|
3539
3526
|
## パフォーマンス
|
|
3540
3527
|
|
|
3541
|
-
|
|
3528
|
+
公式の [js-framework-benchmark](https://github.com/krausest/js-framework-benchmark) で、4.0.0-rc.7 を測った値です(Chrome 154、4 つを 1 回のセッションで。4.0 は全部入りの `auto.min.js`):
|
|
3529
|
+
|
|
3530
|
+
| | vanillajs | 4.0 | [`@wcstack/signals`](../signals/) | 3.5.4 |
|
|
3531
|
+
|---|---:|---:|---:|---:|
|
|
3532
|
+
| CPU(加重幾何平均) | 1.02 | **1.07** | 1.22 | 1.44 |
|
|
3533
|
+
| メモリ(幾何平均) | 1.00 | **1.95** | 1.41 | 4.40 |
|
|
3534
|
+
| 1,000 行を持ったときのメモリ(MB) | 2.03 | **2.97** | 3.72 | 6.35 |
|
|
3535
|
+
|
|
3536
|
+
小さいほど良い値です。上の 2 行は、公式の結果表と同じく、各操作の 4 つの中の最速に対する比の幾何平均です。4.0 の JavaScript の時間は 3.5.4 の約 3 分の 1 です(script だけの幾何平均 2.03 対 6.28、vanillajs を 1)。リポジトリのドライバでの操作ごとの数値は、リリースの一部として 4.0.0 のビルドで計測します。
|
|
3542
3537
|
|
|
3543
3538
|
手元のハードウェアで比べるには、`e2e/bench/` のドライバ(`jsfb-verify.mjs`・`memory-profile.mjs`)を実行してください: 標準の 1,000 / 10,000 行テーブルページを headless Chromium で、両実装を同一セッションで連続して、中央値で計測します。絶対値はマシン状態で ±20% 揺れます。
|
|
3544
3539
|
|
package/README.md
CHANGED
|
@@ -138,7 +138,7 @@ Every row is a section of this README. Unless it appears under [Where the neighb
|
|
|
138
138
|
| **What makes a getter run** | Getters are lazy. Demand comes from a live binding, a `$watch` or a `$stream` `args` — and from nowhere else | [Demand roots](#demand-roots--what-makes-a-getter-run) |
|
|
139
139
|
| **Modularity** | `mount=` grafts a module onto the one tree; `state: path` mounts a subtree onto a component; the per-property form maps single keys, and a mounted component's getters are exported at its mount point | [Volumes](#mounting-additional-state-mount) · [Whole-object mount](#whole-object-mount-state-path) |
|
|
140
140
|
| **Components** | Two mutually exclusive mechanisms: a JavaScript class with `bind-component`, or HTML-only DCC | [Choosing a mechanism](#choosing-a-component-mechanism) |
|
|
141
|
-
| **Wiring to other elements** | The wc-bindable protocol, spread (`...: obj`), `#init=` / `#sync=` authority,
|
|
141
|
+
| **Wiring to other elements** | The wc-bindable protocol, spread (`...: obj`), `#init=` / `#sync=` authority, settable inputs | [Binding authority](#binding-authority-init--sync) · [Spread](#spread-binding-) · [Inputs](#inputs-and-the-attribute-hint) |
|
|
142
142
|
| **Tokens** | Command tokens call an element's methods from state; event tokens carry the element's events back | [Command token](#command-token-method-binding) · [Event token](#event-token-event-binding) |
|
|
143
143
|
| **Time** | `$stream` folds an async source, `$watch` reacts headlessly | [Choosing a time mechanism](#choosing-a-time-mechanism) |
|
|
144
144
|
| **Initialization and lifecycle** | Six ways to supply the state; `$connectedCallback` … `$stateReadyCallback`; `bootstrapState()` / `createState()` | [State initialization](#state-initialization) · [Lifecycle hooks](#lifecycle-hooks) · [API reference](#api-reference) |
|
|
@@ -192,9 +192,9 @@ leaves features out, it can compose them instead:
|
|
|
192
192
|
<script type="importmap">
|
|
193
193
|
{
|
|
194
194
|
"imports": {
|
|
195
|
-
"@wcstack/state/core": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.
|
|
196
|
-
"@wcstack/state/features/temporal": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.
|
|
197
|
-
"@wcstack/state/features/scopes": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.
|
|
195
|
+
"@wcstack/state/core": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.9/dist/split/core.js",
|
|
196
|
+
"@wcstack/state/features/temporal": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.9/dist/split/features/temporal.js",
|
|
197
|
+
"@wcstack/state/features/scopes": "https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.9/dist/split/features/scopes.js"
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
</script>
|
|
@@ -254,7 +254,7 @@ receptacle the owning add-on fills on install).
|
|
|
254
254
|
core, and the add-ons the page names from the same build.
|
|
255
255
|
|
|
256
256
|
```html
|
|
257
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.
|
|
257
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@wcstack/state@4.0.0-rc.9/dist/split/auto.js"></script>
|
|
258
258
|
<wcs-state features="scopes diagnostics">
|
|
259
259
|
<script type="module">
|
|
260
260
|
export default {
|
|
@@ -745,7 +745,7 @@ Runtime reads `customClass.wcBindable.properties + inputs` and expands each name
|
|
|
745
745
|
<wcs-fetch data-wcs="...: usersFetch; status: alternateStatus"></wcs-fetch>
|
|
746
746
|
```
|
|
747
747
|
|
|
748
|
-
**`undefined` is "no opinion"** — when an expanded state path resolves to `undefined` (e.g. the slot object doesn't initialize that input), the property write is **skipped** and the element keeps its own default. You only need to initialize the paths you actually use; `usersFetch: { value: null, loading: false }` is enough even though `<wcs-fetch>` also declares `method` / `manual` / `body`. To explicitly clear a value, assign `null` — `null` is always written. (This skip applies to every property binding that feeds an element input, not just spread.) **Display surfaces are different:** `textContent` / `innerText` / `innerHTML`, mustache and comment-binding text, `attr.*`, `style.*` and `class.*` have no element default worth keeping, so `undefined` and `null` both mean "no value" there — the text becomes empty, the attribute or style is removed, and the class is taken off. `class.*` is the narrow case: only `undefined` and `null` mean "no value"; **any other non-boolean still throws**, because a class binding is a boolean toggle and a truthy string is far more likely a mistake than an intent. Write `class.on: flag|truthy` when you mean "treat it as truthy".
|
|
748
|
+
**`undefined` is "no opinion"** — when an expanded state path resolves to `undefined` (e.g. the slot object doesn't initialize that input), the property write is **skipped** and the element keeps its own default. You only need to initialize the paths you actually use; `usersFetch: { value: null, loading: false }` is enough even though `<wcs-fetch>` also declares `method` / `manual` / `body`. To explicitly clear a value, assign `null` — `null` is always written. (This skip applies to every property binding that feeds an element input, not just spread, and also when the path held a value before: the element keeps the last value state wrote. That is stricter than the wc-bindable applier profile (0.10.0, A2), which writes `undefined` after a value so the element returns to its initial state; state does not claim that profile. Other writers — React 19, a direct assignment — do deliver `undefined`, and the wcstack I/O nodes treat it as "no value supplied".) **Display surfaces are different:** `textContent` / `innerText` / `innerHTML`, mustache and comment-binding text, `attr.*`, `style.*` and `class.*` have no element default worth keeping, so `undefined` and `null` both mean "no value" there — the text becomes empty, the attribute or style is removed, and the class is taken off. `class.*` is the narrow case: only `undefined` and `null` mean "no value"; **any other non-boolean still throws**, because a class binding is a boolean toggle and a truthy string is far more likely a mistake than an intent. Write `class.on: flag|truthy` when you mean "treat it as truthy".
|
|
749
749
|
|
|
750
750
|
**Filters keep the contract.** The emptiness test runs on the value *after* the filters, so a filter that built its result with `String(value)` would turn an absent value back into the characters `"undefined"`. The formatting family (`upper`, `lower`, `capitalize`, `trim`, `slice`, `padStart`, `padEnd`, `repeat`, `reverse`, `truncate`, `unit`) passes `undefined` / `null` straight through instead, so `attr.title: x|trim` removes the attribute just as `attr.title: x` does. Three groups deliberately do **not**: the filters for which an absent value *is* the input (`defaults`, `coalesce`, `nullIfEmpty`, `boolean`, `truthy`, `falsy`, `not`, `eq`, `ne`), the conversions whose whole job is to convert (`int`, `float`, `number`, `string` — `undefined|string` is still `"undefined"`), and the filters that check the value's type (the number, date and array families, e.g. `toFixed` / `date` / `join`). Those last ones throw, which is confined to the one binding and reported through `$errorCallback` — put a `coalesce` in front when the value can legitimately be absent (`price|coalesce(0)|toFixed(2)`).
|
|
751
751
|
|
|
@@ -2610,11 +2610,11 @@ Key rules:
|
|
|
2610
2610
|
- **Not run on a mounted `bind-component` scope** — the `$watch` declaration of a mounted component is ignored with a one-time `wcs/mount-dollar-declaration` warning that points to the root state; this applies to `$stream` and `$renderedCallback` too. A volume refuses `$watch` ([`mount=`](#mounting-additional-state-mount)): declare it on the root with the full path (`"cart.total"`). A plain (unwired Shadow) child owns an independent tree and can declare it.
|
|
2611
2611
|
- **SSR does not run watches** — handler side effects would otherwise execute on both server and client.
|
|
2612
2612
|
|
|
2613
|
-
## Inputs and
|
|
2613
|
+
## Inputs and the `attribute` Hint
|
|
2614
2614
|
|
|
2615
|
-
`wcBindable.inputs` declares
|
|
2615
|
+
`wcBindable.inputs` declares the members state may set (state → element). Under directional initial sync (default on), it is what marks a member as **settable from state**: a member declared only in `properties` becomes output-only and state writes to it are suppressed — see [Binding Authority](#binding-authority-init--sync).
|
|
2616
2616
|
|
|
2617
|
-
`
|
|
2617
|
+
State writes an input's **property**, and only the property. An entry's optional `attribute` names the HTML attribute that corresponds to the property in markup (`<my-chip label-text="…">`); it is a declaration for tooling, as the wc-bindable protocol defines it, and state does not write it (wc-bindable 0.10.0's applier profile, A1: an applier writes the property, never the hinted attribute, and does not fall back to it before the element is upgraded — state waits for the definition). Reflecting a property to its attribute — for `attributeChangedCallback`, CSS attribute selectors or DevTools — is the element's job, in its setter, with the encoding only the element knows (a boolean as a present / absent attribute, `"on"` / `"off"`, JSON …):
|
|
2618
2618
|
|
|
2619
2619
|
```javascript
|
|
2620
2620
|
class MyChip extends HTMLElement {
|
|
@@ -2622,41 +2622,28 @@ class MyChip extends HTMLElement {
|
|
|
2622
2622
|
protocol: "wc-bindable", version: 1,
|
|
2623
2623
|
properties: [],
|
|
2624
2624
|
inputs: [
|
|
2625
|
-
{ name: "
|
|
2626
|
-
{ name: "
|
|
2627
|
-
{ name: "
|
|
2625
|
+
{ name: "labelText", attribute: "label-text" }, // markup: <my-chip label-text="…">
|
|
2626
|
+
{ name: "selected", attribute: "selected" }, // markup: <my-chip selected>
|
|
2627
|
+
{ name: "data" }, // property only
|
|
2628
2628
|
],
|
|
2629
2629
|
};
|
|
2630
|
+
get labelText() { return this.getAttribute("label-text") ?? ""; }
|
|
2631
|
+
set labelText(v) { v == null ? this.removeAttribute("label-text") : this.setAttribute("label-text", v); }
|
|
2632
|
+
get selected() { return this.hasAttribute("selected"); }
|
|
2633
|
+
set selected(v) { this.toggleAttribute("selected", Boolean(v)); }
|
|
2630
2634
|
}
|
|
2631
2635
|
```
|
|
2632
2636
|
|
|
2633
2637
|
```html
|
|
2634
|
-
<my-chip data-wcs="
|
|
2638
|
+
<my-chip data-wcs="labelText: chip.title; selected: chip.on; data: chip.payload"></my-chip>
|
|
2635
2639
|
```
|
|
2636
2640
|
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
```text
|
|
2640
|
-
chip.payload = { id: 1 } → element.data = { id: 1 } and setAttribute("data", '{"id":1}')
|
|
2641
|
-
chip.title = "新着" → element.labelText = "新着" and setAttribute("label-text", "新着")
|
|
2642
|
-
chip.payload = null → element.data = null and removeAttribute("data")
|
|
2643
|
-
```
|
|
2644
|
-
|
|
2645
|
-
Attribute value encoding:
|
|
2646
|
-
|
|
2647
|
-
| Value type | Mirrored attribute |
|
|
2648
|
-
|---|---|
|
|
2649
|
-
| `string` / `number` / `bigint` | `String(value)` |
|
|
2650
|
-
| `true` | the attribute, empty (`""`) |
|
|
2651
|
-
| `false` / `null` / `undefined` | attribute removed |
|
|
2652
|
-
| `object` / `array` | `JSON.stringify(value)` (falls back to `String(value)` on circular references) |
|
|
2641
|
+
`chip.title = "新着"` writes `element.labelText = "新着"`; the setter puts it on `label-text`. `chip.on = false` writes `element.selected = false`; the setter removes `selected`.
|
|
2653
2642
|
|
|
2654
2643
|
Notes:
|
|
2655
2644
|
|
|
2656
|
-
-
|
|
2657
|
-
-
|
|
2658
|
-
- Mirror is best-effort: a `setAttribute` failure is swallowed and does not block the property write
|
|
2659
|
-
- Native HTML elements ignore `inputs` entirely — the mirror only activates for custom elements that expose `static wcBindable`
|
|
2645
|
+
- 3.x also wrote the attribute after the property (`String(value)`, JSON for an object). An element that reflects in its setter is unaffected; one that has no setter and relied on the binder to write its attribute needs a setter now (Migration guide, §3.4).
|
|
2646
|
+
- Native HTML elements ignore `inputs` entirely — the declaration only applies to custom elements that expose `static wcBindable`.
|
|
2660
2647
|
|
|
2661
2648
|
## Choosing a Component Mechanism
|
|
2662
2649
|
|
|
@@ -3552,7 +3539,15 @@ A mounted component runs an engine of its own, whose mounted keys read and write
|
|
|
3552
3539
|
|
|
3553
3540
|
## Performance
|
|
3554
3541
|
|
|
3555
|
-
|
|
3542
|
+
On the official [js-framework-benchmark](https://github.com/krausest/js-framework-benchmark), measured with 4.0.0-rc.7 (Chrome 154, all four in one session, the full `auto.min.js`):
|
|
3543
|
+
|
|
3544
|
+
| | vanillajs | 4.0 | [`@wcstack/signals`](../signals/) | 3.5.4 |
|
|
3545
|
+
|---|---:|---:|---:|---:|
|
|
3546
|
+
| CPU (weighted geometric mean) | 1.02 | **1.07** | 1.22 | 1.44 |
|
|
3547
|
+
| Memory (geometric mean) | 1.00 | **1.95** | 1.41 | 4.40 |
|
|
3548
|
+
| Run memory, 1,000 rows (MB) | 2.03 | **2.97** | 3.72 | 6.35 |
|
|
3549
|
+
|
|
3550
|
+
Lower is better. The first two rows are geometric means of each operation's factor against the fastest of the four, as in the official results table. 4.0's JavaScript time is about a third of 3.5.4's (script-only geometric mean 2.03 against 6.28, vanillajs = 1). The per-operation numbers with the repository's own drivers are taken with the 4.0.0 build as part of the release.
|
|
3556
3551
|
|
|
3557
3552
|
To compare on your own hardware, run the drivers in `e2e/bench/` (`jsfb-verify.mjs`, `memory-profile.mjs`): they measure the standard 1,000 / 10,000-row table page in headless Chromium, both implementations back-to-back in the same session, as medians. Absolute values swing by ±20% with machine state.
|
|
3558
3553
|
|