@wc-bindable/stencil 0.7.0 → 0.8.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 (2) hide show
  1. package/README.md +92 -88
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,88 +1,92 @@
1
- # @wc-bindable/stencil
2
-
3
- Stencil adapter for the **wc-bindable** protocol.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm install @wc-bindable/stencil @stencil/core
9
- ```
10
-
11
- ## Usage
12
-
13
- ```tsx
14
- import { Component, Element, h } from "@stencil/core";
15
- import { WcBindableController } from "@wc-bindable/stencil";
16
-
17
- @Component({ tag: "todo-view" })
18
- export class TodoView {
19
- @Element() host!: HTMLElement;
20
-
21
- private todoRef?: HTMLElement;
22
- private todo = new WcBindableController<{ items: string[]; count: number }>(
23
- this,
24
- () => this.todoRef,
25
- { items: [], count: 0 },
26
- );
27
-
28
- connectedCallback() {
29
- this.todo.connect();
30
- }
31
-
32
- disconnectedCallback() {
33
- this.todo.disconnect();
34
- }
35
-
36
- componentDidRender() {
37
- this.todo.update();
38
- }
39
-
40
- render() {
41
- return (
42
- <div>
43
- <my-todo ref={(el) => (this.todoRef = el)}></my-todo>
44
- <p>Count: {this.todo.values.count}</p>
45
- <ul>
46
- {this.todo.values.items.map((i) => (
47
- <li>{i}</li>
48
- ))}
49
- </ul>
50
- </div>
51
- );
52
- }
53
- }
54
- ```
55
-
56
- If the host itself is the bindable element you can pass it directly:
57
-
58
- ```ts
59
- this.controller = new WcBindableController(this, this.host);
60
- ```
61
-
62
- ## API
63
-
64
- ### `new WcBindableController<V>(host, target, initialValues?)`
65
-
66
- | Parameter | Type | Description |
67
- |---|---|---|
68
- | `host` | `HTMLElement \| object` | Stencil component instance or host element — passed to `forceUpdate()` when a bindable property changes |
69
- | `target` | `HTMLElement \| null \| undefined \| () => HTMLElement \| null \| undefined` | The bindable element, or a getter that returns it once it is rendered |
70
- | `initialValues` | `Partial<V>` | Optional initial values for bindable properties |
71
-
72
- | Member | Type | Description |
73
- |---|---|---|
74
- | `values` | `V` | Latest property values; reading from `render()` becomes reactive via `forceUpdate(host)` |
75
-
76
- | Method | Description |
77
- |---|---|
78
- | `connect()` | Call from `connectedCallback()` to start listening |
79
- | `disconnect()` | Call from `disconnectedCallback()` to remove listeners |
80
- | `update()` | Call from `componentDidRender()` / `componentDidUpdate()` to rebind if the target element changed |
81
-
82
- - On each `update()` the target is re-resolved; if it changed, listeners are rebound to the new element.
83
- - Calls `forceUpdate(host)` whenever a bindable property changes.
84
- - If the element does not implement `wc-bindable`, the controller is a no-op.
85
-
86
- ## License
87
-
88
- MIT
1
+ # @wc-bindable/stencil
2
+
3
+ Stencil adapter for the **wc-bindable** protocol.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @wc-bindable/stencil @stencil/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { Component, Element, h } from "@stencil/core";
15
+ import { WcBindableController } from "@wc-bindable/stencil";
16
+
17
+ @Component({ tag: "todo-view" })
18
+ export class TodoView {
19
+ @Element() host!: HTMLElement;
20
+
21
+ private todoRef?: HTMLElement;
22
+ private todo = new WcBindableController<{ items: string[]; count: number }>(
23
+ this,
24
+ () => this.todoRef,
25
+ { items: [], count: 0 },
26
+ );
27
+
28
+ connectedCallback() {
29
+ this.todo.connect();
30
+ }
31
+
32
+ disconnectedCallback() {
33
+ this.todo.disconnect();
34
+ }
35
+
36
+ componentDidRender() {
37
+ this.todo.update();
38
+ }
39
+
40
+ render() {
41
+ return (
42
+ <div>
43
+ <my-todo ref={(el) => (this.todoRef = el)}></my-todo>
44
+ <p>Count: {this.todo.values.count}</p>
45
+ <ul>
46
+ {this.todo.values.items.map((i) => (
47
+ <li>{i}</li>
48
+ ))}
49
+ </ul>
50
+ </div>
51
+ );
52
+ }
53
+ }
54
+ ```
55
+
56
+ If the host itself is the bindable element you can pass it directly:
57
+
58
+ ```ts
59
+ this.controller = new WcBindableController(this, this.host);
60
+ ```
61
+
62
+ ## API
63
+
64
+ ### `new WcBindableController<V>(host, target, initialValues?)`
65
+
66
+ | Parameter | Type | Description |
67
+ |---|---|---|
68
+ | `host` | `HTMLElement \| object` | Stencil component instance or host element — passed to `forceUpdate()` when a bindable property changes |
69
+ | `target` | `HTMLElement \| null \| undefined \| () => HTMLElement \| null \| undefined` | The bindable element, or a getter that returns it once it is rendered |
70
+ | `initialValues` | `Partial<V>` | Optional initial values for bindable properties |
71
+
72
+ | Member | Type | Description |
73
+ |---|---|---|
74
+ | `values` | `V` | Latest property values; reading from `render()` becomes reactive via `forceUpdate(host)` |
75
+
76
+ | Method | Description |
77
+ |---|---|
78
+ | `connect()` | Call from `connectedCallback()` to start listening |
79
+ | `disconnect()` | Call from `disconnectedCallback()` to remove listeners |
80
+ | `update()` | Call from `componentDidRender()` / `componentDidUpdate()` to rebind if the target element changed |
81
+
82
+ - On each `update()` the target is re-resolved; if it changed, listeners are rebound to the new element.
83
+ - Calls `forceUpdate(host)` whenever a bindable property changes.
84
+ - If the element does not implement `wc-bindable`, the controller is a no-op.
85
+
86
+ ## Specification
87
+
88
+ The protocol contract this adapter implements lives in [SPEC.md](../../SPEC.md); the optional input/command invocation surface and the remote wire format live in [SPEC-extensions.md](../../SPEC-extensions.md). Runnable conformance vectors are in [CONFORMANCE.md](../../CONFORMANCE.md).
89
+
90
+ ## License
91
+
92
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wc-bindable/stencil",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Stencil adapter for wc-bindable protocol",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "dev": "tsc --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@wc-bindable/core": "^0.6.0"
24
+ "@wc-bindable/core": "^0.8.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@stencil/core": ">=3"