@wc-bindable/stencil 0.7.1 → 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 CHANGED
@@ -61,7 +61,7 @@ this.controller = new WcBindableController(this, this.host);
61
61
 
62
62
  ## API
63
63
 
64
- ### `new WcBindableController<V>(host, target, initialValues?)`
64
+ ### `new WcBindableController<V>(host, target, initialValues?, options?)`
65
65
 
66
66
  | Parameter | Type | Description |
67
67
  |---|---|---|
@@ -81,7 +81,24 @@ this.controller = new WcBindableController(this, this.host);
81
81
 
82
82
  - On each `update()` the target is re-resolved; if it changed, listeners are rebound to the new element.
83
83
  - Calls `forceUpdate(host)` whenever a bindable property changes.
84
- - If the element does not implement `wc-bindable`, the controller is a no-op.
84
+ - If the element does not implement `wc-bindable` — and is not a custom element still waiting for its definition — the controller is a no-op. See [Late-defined elements](#late-defined-elements).
85
+
86
+ ## Late-defined elements
87
+
88
+ `bind()` is called with `syncOn: "define"` by default, so an element whose custom element
89
+ definition arrives *after* this adapter runs — import-map autoloading, a CDN
90
+ `<script type="module">`, a code-split route — still binds once the definition lands. Nothing
91
+ has to re-run, and no re-render is needed.
92
+
93
+ Before this default, a not-yet-upgraded element was skipped permanently and silently: discovery
94
+ failed, the adapter returned early, and because the element keeps its identity across upgrade
95
+ nothing ever noticed. Opt back into that behavior with `syncOn: "call"`.
96
+
97
+ ```ts
98
+ new WcBindableController(host, () => this.el, { value: "" }, { syncOn: "call" });
99
+ ```
100
+
101
+ See [SPEC.md § Deferring Discovery Until Definition](../../SPEC.md#deferring-discovery-until-definition).
85
102
 
86
103
  ## Specification
87
104
 
package/dist/index.d.ts CHANGED
@@ -1,12 +1,24 @@
1
+ import { type BindOptions } from "@wc-bindable/core";
1
2
  export type WcBindableTarget = HTMLElement | null | undefined | (() => HTMLElement | null | undefined);
2
3
  export type WcBindableHost = HTMLElement | object;
4
+ export interface WcBindableControllerOptions {
5
+ /**
6
+ * Forwarded to `bind()`. Defaults to `"define"` so a target whose
7
+ * definition arrives after `connect()` 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
+ * until something else triggers a re-attach.
11
+ */
12
+ syncOn?: BindOptions["syncOn"];
13
+ }
3
14
  export declare class WcBindableController<V extends object = Record<string, unknown>> {
4
15
  values: V;
5
16
  private readonly host;
6
17
  private readonly getTarget;
18
+ private readonly syncOn;
7
19
  private currentTarget;
8
20
  private unbind?;
9
- constructor(host: WcBindableHost, target: WcBindableTarget, initialValues?: Partial<V>);
21
+ constructor(host: WcBindableHost, target: WcBindableTarget, initialValues?: Partial<V>, options?: WcBindableControllerOptions);
10
22
  connect(): void;
11
23
  disconnect(): void;
12
24
  update(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,gBAAgB,GACxB,WAAW,GACX,IAAI,GACJ,SAAS,GACT,CAAC,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,MAAM,CAAC;AAElD,qBAAa,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC1E,MAAM,EAAE,CAAC,CAAC;IAEV,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuC;IACjE,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,MAAM,CAAC,CAAa;gBAG1B,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,gBAAgB,EACxB,aAAa,GAAE,OAAO,CAAC,CAAC,CAAM;IAQhC,OAAO,IAAI,IAAI;IAIf,UAAU,IAAI,IAAI;IAIlB,MAAM,IAAI,IAAI;IAQd,OAAO,CAAC,MAAM;IAcd,OAAO,CAAC,MAAM;CAKf"}
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,gBAAgB,GACxB,WAAW,GACX,IAAI,GACJ,SAAS,GACT,CAAC,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,MAAM,CAAC;AAElD,MAAM,WAAW,2BAA2B;IAC1C;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;CAChC;AAED,qBAAa,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC1E,MAAM,EAAE,CAAC,CAAC;IAEV,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuC;IACjE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAC/C,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,MAAM,CAAC,CAAa;gBAG1B,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,gBAAgB,EACxB,aAAa,GAAE,OAAO,CAAC,CAAC,CAAM,EAC9B,OAAO,GAAE,2BAAgC;IAS3C,OAAO,IAAI,IAAI;IAIf,UAAU,IAAI,IAAI;IAIlB,MAAM,IAAI,IAAI;IAQd,OAAO,CAAC,MAAM;IAoBd,OAAO,CAAC,MAAM;CAKf"}
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { forceUpdate } from "@stencil/core";
2
- import { bind, isWcBindable } from "@wc-bindable/core";
2
+ import { bind } from "@wc-bindable/core";
3
3
  export class WcBindableController {
4
- constructor(host, target, initialValues = {}) {
4
+ constructor(host, target, initialValues = {}, options = {}) {
5
5
  this.currentTarget = null;
6
6
  this.host = host;
7
7
  this.values = { ...initialValues };
8
+ this.syncOn = options.syncOn ?? "define";
8
9
  this.getTarget =
9
10
  typeof target === "function" ? target : () => target ?? null;
10
11
  }
@@ -23,15 +24,22 @@ export class WcBindableController {
23
24
  }
24
25
  attach() {
25
26
  const el = this.getTarget() ?? null;
26
- if (!el || !isWcBindable(el)) {
27
- this.currentTarget = el;
28
- return;
29
- }
30
27
  this.currentTarget = el;
28
+ if (!el)
29
+ return;
30
+ // No `isWcBindable()` gate: bind() already returns a no-op cleanup for
31
+ // a non-bindable target, and the gate is precisely what defeated
32
+ // `syncOn: "define"` — it fails for a not-yet-upgraded custom element.
33
+ // Note this also stops `update()` from re-attaching on every host
34
+ // update for a target that is not bindable: `unbind` is now always set,
35
+ // so the `(next && !this.unbind)` re-attach condition no longer fires
36
+ // repeatedly. That retry loop was the only thing that ever recovered a
37
+ // late-defined target here, and the deferred bind replaces it with a
38
+ // single wait.
31
39
  this.unbind = bind(el, (name, value) => {
32
40
  this.values = { ...this.values, [name]: value };
33
41
  forceUpdate(this.host);
34
- });
42
+ }, { syncOn: this.syncOn });
35
43
  }
36
44
  detach() {
37
45
  this.unbind?.();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUvD,MAAM,OAAO,oBAAoB;IAQ/B,YACE,IAAoB,EACpB,MAAwB,EACxB,gBAA4B,EAAE;QANxB,kBAAa,GAAuB,IAAI,CAAC;QAQ/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,aAAa,EAAO,CAAC;QACxC,IAAI,CAAC,SAAS;YACZ,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC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AC,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC;YAChD,WAAW,CAAC,IAAI,CAAC,IAAmB,CAAC,CAAC;QACxC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9B,CAAC;IAEO,MAAM;QACZ,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wc-bindable/stencil",
3
- "version": "0.7.1",
3
+ "version": "0.9.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.7.1"
24
+ "@wc-bindable/core": "^0.9.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@stencil/core": ">=3"