@wc-bindable/marko 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.
- package/README.md +80 -76
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,76 +1,80 @@
|
|
|
1
|
-
# @wc-bindable/marko
|
|
2
|
-
|
|
3
|
-
Marko adapter for the **wc-bindable** protocol.
|
|
4
|
-
|
|
5
|
-
The adapter is a single framework-agnostic helper that wires `bind()` from
|
|
6
|
-
`@wc-bindable/core` into Marko's own mount/destroy lifecycle. It is
|
|
7
|
-
version-agnostic — the same import works in **Marko 5** (class components) and
|
|
8
|
-
**Marko 6** (Tags API).
|
|
9
|
-
|
|
10
|
-
## Install
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
npm install @wc-bindable/marko marko
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## API
|
|
17
|
-
|
|
18
|
-
### `wcBindable(el, onUpdate): unbind`
|
|
19
|
-
|
|
20
|
-
| Parameter | Type | Description |
|
|
21
|
-
|---|---|---|
|
|
22
|
-
| `el` | `HTMLElement` | The Web Component DOM node |
|
|
23
|
-
| `onUpdate` | `(name: string, value: unknown) => void` | Called for each declared property on the initial sync and on every subsequent change event |
|
|
24
|
-
|
|
25
|
-
Returns an `unbind` function. If `el` does not implement the wc-bindable
|
|
26
|
-
protocol, the helper is a no-op and the returned function is safe to call.
|
|
27
|
-
|
|
28
|
-
## Marko 6 (Tags API)
|
|
29
|
-
|
|
30
|
-
Capture the element with a tag variable, then call the helper from `<lifecycle>`:
|
|
31
|
-
|
|
32
|
-
```marko
|
|
33
|
-
import { wcBindable } from "@wc-bindable/marko";
|
|
34
|
-
|
|
35
|
-
<let/state = { value: "" } />
|
|
36
|
-
<my-input/inputEl />
|
|
37
|
-
<lifecycle
|
|
38
|
-
onMount() { this.unbind = wcBindable(inputEl, (n, v) => state = { ...state, [n]: v }); }
|
|
39
|
-
onDestroy() { this.unbind?.(); }
|
|
40
|
-
/>
|
|
41
|
-
<output>${state.value}</output>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Marko 5 (class components)
|
|
45
|
-
|
|
46
|
-
Use a `key=` ref + `getEl()` from `onMount`, release in `onDestroy`:
|
|
47
|
-
|
|
48
|
-
```marko
|
|
49
|
-
import { wcBindable } from "@wc-bindable/marko";
|
|
50
|
-
|
|
51
|
-
class {
|
|
52
|
-
onCreate() { this.state = { value: "" }; }
|
|
53
|
-
onMount() {
|
|
54
|
-
this.unbind = wcBindable(this.getEl("input"), (name, value) => {
|
|
55
|
-
this.state[name] = value;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
onDestroy() { if (this.unbind) this.unbind(); }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
<my-input key="input" />
|
|
62
|
-
<output>${state.value}</output>
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
If your Web Component's tag name contains a hyphen, Marko 5 may try to resolve
|
|
66
|
-
it as a custom Marko component. Use the dynamic-tag syntax to render it as a
|
|
67
|
-
plain HTML element:
|
|
68
|
-
|
|
69
|
-
```marko
|
|
70
|
-
$ const TAG = "my-input";
|
|
71
|
-
<${TAG} key="input"/>
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
##
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
# @wc-bindable/marko
|
|
2
|
+
|
|
3
|
+
Marko adapter for the **wc-bindable** protocol.
|
|
4
|
+
|
|
5
|
+
The adapter is a single framework-agnostic helper that wires `bind()` from
|
|
6
|
+
`@wc-bindable/core` into Marko's own mount/destroy lifecycle. It is
|
|
7
|
+
version-agnostic — the same import works in **Marko 5** (class components) and
|
|
8
|
+
**Marko 6** (Tags API).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @wc-bindable/marko marko
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## API
|
|
17
|
+
|
|
18
|
+
### `wcBindable(el, onUpdate): unbind`
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Description |
|
|
21
|
+
|---|---|---|
|
|
22
|
+
| `el` | `HTMLElement` | The Web Component DOM node |
|
|
23
|
+
| `onUpdate` | `(name: string, value: unknown) => void` | Called for each declared property on the initial sync and on every subsequent change event |
|
|
24
|
+
|
|
25
|
+
Returns an `unbind` function. If `el` does not implement the wc-bindable
|
|
26
|
+
protocol, the helper is a no-op and the returned function is safe to call.
|
|
27
|
+
|
|
28
|
+
## Marko 6 (Tags API)
|
|
29
|
+
|
|
30
|
+
Capture the element with a tag variable, then call the helper from `<lifecycle>`:
|
|
31
|
+
|
|
32
|
+
```marko
|
|
33
|
+
import { wcBindable } from "@wc-bindable/marko";
|
|
34
|
+
|
|
35
|
+
<let/state = { value: "" } />
|
|
36
|
+
<my-input/inputEl />
|
|
37
|
+
<lifecycle
|
|
38
|
+
onMount() { this.unbind = wcBindable(inputEl, (n, v) => state = { ...state, [n]: v }); }
|
|
39
|
+
onDestroy() { this.unbind?.(); }
|
|
40
|
+
/>
|
|
41
|
+
<output>${state.value}</output>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Marko 5 (class components)
|
|
45
|
+
|
|
46
|
+
Use a `key=` ref + `getEl()` from `onMount`, release in `onDestroy`:
|
|
47
|
+
|
|
48
|
+
```marko
|
|
49
|
+
import { wcBindable } from "@wc-bindable/marko";
|
|
50
|
+
|
|
51
|
+
class {
|
|
52
|
+
onCreate() { this.state = { value: "" }; }
|
|
53
|
+
onMount() {
|
|
54
|
+
this.unbind = wcBindable(this.getEl("input"), (name, value) => {
|
|
55
|
+
this.state[name] = value;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
onDestroy() { if (this.unbind) this.unbind(); }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
<my-input key="input" />
|
|
62
|
+
<output>${state.value}</output>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
If your Web Component's tag name contains a hyphen, Marko 5 may try to resolve
|
|
66
|
+
it as a custom Marko component. Use the dynamic-tag syntax to render it as a
|
|
67
|
+
plain HTML element:
|
|
68
|
+
|
|
69
|
+
```marko
|
|
70
|
+
$ const TAG = "my-input";
|
|
71
|
+
<${TAG} key="input"/>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Specification
|
|
75
|
+
|
|
76
|
+
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).
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wc-bindable/marko",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Marko adapter for wc-bindable protocol",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test:integration": "vitest run --config vitest.integration.config.ts integration"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@wc-bindable/core": "^0.
|
|
27
|
+
"@wc-bindable/core": "^0.8.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"marko": ">=5"
|