@wc-bindable/mithril 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/README.md +19 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install @wc-bindable/mithril mithril
|
|
|
14
14
|
|
|
15
15
|
## API
|
|
16
16
|
|
|
17
|
-
### `wcBindable(el, onUpdate): unbind`
|
|
17
|
+
### `wcBindable(el, onUpdate, options?): unbind`
|
|
18
18
|
|
|
19
19
|
Low-level helper. Call it from any lifecycle hook that gives you the DOM node;
|
|
20
20
|
the adapter does no redraw — you decide what to do with each update.
|
|
@@ -117,6 +117,24 @@ const Form = () => {
|
|
|
117
117
|
};
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
## Late-defined elements
|
|
121
|
+
|
|
122
|
+
`bind()` is called with `syncOn: "define"` by default, so an element whose custom element
|
|
123
|
+
definition arrives *after* this adapter runs — import-map autoloading, a CDN
|
|
124
|
+
`<script type="module">`, a code-split route — still binds once the definition lands. Nothing
|
|
125
|
+
has to re-run, and no re-render is needed.
|
|
126
|
+
|
|
127
|
+
Before this default, a not-yet-upgraded element was skipped permanently and silently: discovery
|
|
128
|
+
failed, the adapter returned early, and because the element keeps its identity across upgrade
|
|
129
|
+
nothing ever noticed. Opt back into that behavior with `syncOn: "call"`.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
wcBindable(el, onUpdate, { syncOn: "call" });
|
|
133
|
+
createWcBindable({ value: "" }, { syncOn: "call" });
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
See [SPEC.md § Deferring Discovery Until Definition](../../SPEC.md#deferring-discovery-until-definition).
|
|
137
|
+
|
|
120
138
|
## Specification
|
|
121
139
|
|
|
122
140
|
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).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
import { type BindOptions } from "@wc-bindable/core";
|
|
1
2
|
export type UnbindFn = () => void;
|
|
2
3
|
export type OnUpdate = (name: string, value: unknown) => void;
|
|
3
|
-
export
|
|
4
|
-
|
|
4
|
+
export interface WcBindableOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Forwarded to `bind()`. Defaults to `"define"` so an element whose
|
|
7
|
+
* definition arrives after this call still binds — see SPEC.md
|
|
8
|
+
* § Deferring Discovery Until Definition. Pass `"call"` to opt back into
|
|
9
|
+
* the historical behavior, where a not-yet-upgraded element is skipped
|
|
10
|
+
* permanently.
|
|
11
|
+
*/
|
|
12
|
+
syncOn?: BindOptions["syncOn"];
|
|
13
|
+
}
|
|
14
|
+
export declare function wcBindable(el: HTMLElement, onUpdate: OnUpdate, options?: WcBindableOptions): UnbindFn;
|
|
15
|
+
export interface CreateWcBindableOptions extends WcBindableOptions {
|
|
5
16
|
redraw?: () => void;
|
|
6
17
|
}
|
|
7
18
|
export interface WcBindableState<V extends object> {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE3D,MAAM,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC;AAClC,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AAE9D,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAChC;AAED,wBAAgB,UAAU,CACxB,EAAE,EAAE,WAAW,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,iBAAsB,GAC9B,QAAQ,CAMV;AAED,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM;IAC/C,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACxC,QAAQ,IAAI,IAAI,CAAC;CAClB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzE,aAAa,GAAE,OAAO,CAAC,CAAC,CAAM,EAC9B,OAAO,GAAE,uBAA4B,GACpC,eAAe,CAAC,CAAC,CAAC,CAuBpB"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import m from "mithril";
|
|
2
|
-
import { bind
|
|
3
|
-
export function wcBindable(el, onUpdate) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { bind } from "@wc-bindable/core";
|
|
3
|
+
export function wcBindable(el, onUpdate, options = {}) {
|
|
4
|
+
// No `isWcBindable()` gate: bind() already returns a no-op cleanup for a
|
|
5
|
+
// non-bindable target, and the gate is precisely what defeated
|
|
6
|
+
// `syncOn: "define"` — it fails for a not-yet-upgraded custom element,
|
|
7
|
+
// and nothing re-runs this call on upgrade.
|
|
8
|
+
return bind(el, onUpdate, { syncOn: options.syncOn ?? "define" });
|
|
7
9
|
}
|
|
8
10
|
export function createWcBindable(initialValues = {}, options = {}) {
|
|
9
11
|
const redraw = options.redraw ?? (() => m.redraw());
|
|
@@ -15,12 +17,10 @@ export function createWcBindable(initialValues = {}, options = {}) {
|
|
|
15
17
|
},
|
|
16
18
|
oncreate(vnode) {
|
|
17
19
|
const el = vnode.dom;
|
|
18
|
-
if (!isWcBindable(el))
|
|
19
|
-
return;
|
|
20
20
|
unbind = bind(el, (name, value) => {
|
|
21
21
|
state[name] = value;
|
|
22
22
|
redraw();
|
|
23
|
-
});
|
|
23
|
+
}, { syncOn: options.syncOn ?? "define" });
|
|
24
24
|
},
|
|
25
25
|
onremove() {
|
|
26
26
|
if (unbind) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,SAAS,CAAC;AACxB,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,SAAS,CAAC;AACxB,OAAO,EAAE,IAAI,EAAoB,MAAM,mBAAmB,CAAC;AAgB3D,MAAM,UAAU,UAAU,CACxB,EAAe,EACf,QAAkB,EAClB,UAA6B,EAAE;IAE/B,yEAAyE;IACzE,+DAA+D;IAC/D,uEAAuE;IACvE,4CAA4C;IAC5C,OAAO,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC,CAAC;AACpE,CAAC;AAYD,MAAM,UAAU,gBAAgB,CAC9B,gBAA4B,EAAE,EAC9B,UAAmC,EAAE;IAErC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,EAAE,GAAI,aAAmB,EAAE,CAAC;IAC1C,IAAI,MAAM,GAAoB,IAAI,CAAC;IAEnC,OAAO;QACL,IAAI,MAAM;YACR,OAAO,KAAK,CAAC;QACf,CAAC;QACD,QAAQ,CAAC,KAAK;YACZ,MAAM,EAAE,GAAG,KAAK,CAAC,GAAkB,CAAC;YACpC,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;gBAC/B,KAAiC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;gBACjD,MAAM,EAAE,CAAC;YACX,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC,CAAC;QAC7C,CAAC;QACD,QAAQ;YACN,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,EAAE,CAAC;gBACT,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wc-bindable/mithril",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Mithril.js adapter for wc-bindable protocol",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test:watch": "vitest tests"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@wc-bindable/core": "^0.
|
|
26
|
+
"@wc-bindable/core": "^0.9.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"mithril": ">=2"
|