@wc-bindable/rxjs 0.8.0 → 0.10.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
@@ -14,7 +14,7 @@ npm install @wc-bindable/rxjs rxjs
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 with the DOM node and a callback that receives every
20
20
  property update. The adapter does no reactivity wiring — you decide what to do
@@ -28,7 +28,7 @@ with each update (typically calling `.next()` on a `Subject` you control).
28
28
  Returns an `unbind` function. If `el` does not implement the wc-bindable
29
29
  protocol, the helper is a no-op and the returned function is safe to call.
30
30
 
31
- ### `createWcBindable<V>(initialValues?): WcBindableBinder<V>`
31
+ ### `createWcBindable<V>(initialValues?, options?): WcBindableBinder<V>`
32
32
 
33
33
  Stateful helper. Pre-creates one `BehaviorSubject` per key in `initialValues`
34
34
  and keeps each subject's value in sync with the component's matching declared
@@ -112,6 +112,31 @@ const unbind = wcBindable(el, (name, v) => {
112
112
  unbind();
113
113
  ```
114
114
 
115
+ ## Late-defined elements
116
+
117
+ This package binds with a deferral by default, so an element whose custom element definition
118
+ arrives *after* the binder runs — import-map autoloading, a CDN `<script type="module">`, a
119
+ code-split route — still binds once the definition lands.
120
+
121
+ | Entry point | Default `syncOn` | Why |
122
+ |---|---|---|
123
+ | `wcBindable(el, onUpdate)` | `"define"` | Wait for the definition, then register as usual |
124
+ | `createWcBindable().bind(el)` | `["define", "connect"]` | This binder is handed a **detached** element, so it also has to defer the initial-value read until the element is attached — the two deferrals compose |
125
+
126
+ Before these defaults, a not-yet-upgraded element was skipped permanently and silently: discovery
127
+ failed, the binder returned early, and because the element keeps its identity across upgrade
128
+ nothing ever noticed. `syncOn: "connect"` alone did not help — the discovery gate runs first.
129
+
130
+ Opt back into the historical behavior with `syncOn`:
131
+
132
+ ```ts
133
+ wcBindable(el, onUpdate, { syncOn: "call" });
134
+ createWcBindable({ value: "" }, { syncOn: "connect" });
135
+ ```
136
+
137
+ See [SPEC.md § Deferring Discovery Until Definition](../../SPEC.md#deferring-discovery-until-definition)
138
+ and [§ Composing `syncOn` modes](../../SPEC.md#composing-syncon-modes).
139
+
115
140
  ## Specification
116
141
 
117
142
  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,17 @@
1
1
  import { BehaviorSubject } from "rxjs";
2
+ import { type BindOptions } from "@wc-bindable/core";
2
3
  export type UnbindFn = () => void;
3
4
  export type OnUpdate = (name: string, value: unknown) => void;
4
- export declare function wcBindable(el: Element, onUpdate: OnUpdate): UnbindFn;
5
+ export interface WcBindableOptions {
6
+ /**
7
+ * Forwarded to `bind()`. Note the two different defaults: `wcBindable()`
8
+ * uses `"define"`, while `createWcBindable().bind()` uses
9
+ * `["define", "connect"]` because it is handed a detached element. Pass
10
+ * `"call"` to opt back into the historical synchronous behavior.
11
+ */
12
+ syncOn?: BindOptions["syncOn"];
13
+ }
14
+ export declare function wcBindable(el: Element, onUpdate: OnUpdate, options?: WcBindableOptions): UnbindFn;
5
15
  export type WcBindableSubjects<V extends object> = {
6
16
  [K in keyof V]: BehaviorSubject<V[K]>;
7
17
  };
@@ -10,5 +20,5 @@ export interface WcBindableBinder<V extends object> {
10
20
  bind(el: Element): void;
11
21
  unbind(): void;
12
22
  }
13
- export declare function createWcBindable<V extends object = Record<string, unknown>>(initialValues?: Partial<V>): WcBindableBinder<V>;
23
+ export declare function createWcBindable<V extends object = Record<string, unknown>>(initialValues?: Partial<V>, options?: WcBindableOptions): WcBindableBinder<V>;
14
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],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,CAAC,CAAC;CAChC;AAED,wBAAgB,UAAU,CACxB,EAAE,EAAE,OAAO,EACX,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,iBAAsB,GAC9B,QAAQ,CAMV;AAED,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI;KAChD,CAAC,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM;IAChD,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzE,aAAa,GAAE,OAAO,CAAC,CAAC,CAAM,EAC9B,OAAO,GAAE,iBAAsB,GAC9B,gBAAgB,CAAC,CAAC,CAAC,CA8CrB"}
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import { BehaviorSubject } from "rxjs";
2
- import { bind, isWcBindable } from "@wc-bindable/core";
3
- export function wcBindable(el, onUpdate) {
4
- if (!isWcBindable(el))
5
- return () => { };
6
- return bind(el, onUpdate);
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
- export function createWcBindable(initialValues = {}) {
10
+ export function createWcBindable(initialValues = {}, options = {}) {
9
11
  const subjects = {};
10
12
  for (const key of Object.keys(initialValues)) {
11
13
  subjects[key] = new BehaviorSubject(initialValues[key]);
@@ -20,11 +22,17 @@ export function createWcBindable(initialValues = {}) {
20
22
  unbindFn();
21
23
  unbindFn = null;
22
24
  }
23
- if (!isWcBindable(el))
24
- return;
25
- // syncOn: "connect" defers the initial-value read until the element is
26
- // attached to the document so users do not have to sequence
27
- // bind() after appendChild() manually.
25
+ // syncOn: ["define", "connect"] because this binder is handed a
26
+ // detached element built from a definition that may not have loaded
27
+ // yet, and both deferrals are needed:
28
+ // - "define" so a not-yet-upgraded element is not skipped
29
+ // permanently. Without it, the discovery gate fails and nothing
30
+ // re-runs when the definition arrives.
31
+ // - "connect" so the initial-value read still happens after the
32
+ // element is attached, and users do not have to sequence bind()
33
+ // after appendChild() manually.
34
+ // The `isWcBindable()` gate is gone for the same reason: it ran
35
+ // before "define" could ever help.
28
36
  unbindFn = bind(el, (name, value) => {
29
37
  const existing = subjects[name];
30
38
  if (existing) {
@@ -33,7 +41,7 @@ export function createWcBindable(initialValues = {}) {
33
41
  else {
34
42
  subjects[name] = new BehaviorSubject(value);
35
43
  }
36
- }, { syncOn: "connect" });
44
+ }, { syncOn: options.syncOn ?? ["define", "connect"] });
37
45
  },
38
46
  unbind() {
39
47
  if (unbindFn) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKvD,MAAM,UAAU,UAAU,CAAC,EAAW,EAAE,QAAkB;IACxD,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;QAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IACvC,OAAO,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC5B,CAAC;AAYD,MAAM,UAAU,gBAAgB,CAC9B,gBAA4B,EAAE;IAE9B,MAAM,QAAQ,GAA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,IAAI,eAAe,CAAU,KAAK,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,MAAM;YACJ,IAAI,QAAQ,EAAE,CAAC;gBACb,QAAQ,EAAE,CAAC;gBACX,QAAQ,GAAG,IAAI,CAAC;YAClB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wc-bindable/rxjs",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "RxJS 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.8.0"
26
+ "@wc-bindable/core": "^0.10.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "rxjs": ">=7"