assign-gingerly 0.0.40 → 0.0.41

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
@@ -4617,13 +4617,24 @@ customElements.assignFeatures(MyBehaviors, { anything: { spawn: AnythingImpl } }
4617
4617
 
4618
4618
  ### Lifecycle callback forwarding with `callbackForwarding`
4619
4619
 
4620
- Features can receive custom element lifecycle callbacks by declaring `callbackForwarding` in their config:
4620
+ Features can receive custom element lifecycle callbacks by declaring `callbackForwarding` in their config. This can be specified by the feature author (in `static supportedFeatures`) and/or by the consumer (in `assignFeatures`). Both are merged — the author declares what the feature intrinsically needs, the consumer can add more:
4621
4621
 
4622
4622
  ```JavaScript
4623
+ // Author declares what the feature needs
4624
+ class MyElement extends HTMLElement {
4625
+ static supportedFeatures = {
4626
+ reflector: {
4627
+ fallbackSpawn: Reflector,
4628
+ callbackForwarding: ['connectedCallback', 'disconnectedCallback']
4629
+ }
4630
+ }
4631
+ }
4632
+
4633
+ // Consumer can add more (but not remove author's)
4623
4634
  customElements.assignFeatures(MyElement, {
4624
4635
  reflector: {
4625
4636
  spawn: Reflector,
4626
- callbackForwarding: ['connectedCallback', 'disconnectedCallback']
4637
+ callbackForwarding: ['adoptedCallback'] // merged with author's
4627
4638
  }
4628
4639
  });
4629
4640
  ```
package/assignFeatures.js CHANGED
@@ -401,10 +401,15 @@ export function assignFeatures(ctr, features, featuresRegistry) {
401
401
  featuresRegistry.set(ctr, key, features[key]);
402
402
  // 5. Install the lazy getter on the prototype
403
403
  installFeatureGetter(ctr, key, featuresRegistry);
404
- // 6. Install callback forwarding if configured
404
+ // 6. Install callback forwarding if configured (merge author + consumer)
405
405
  const featureConfig = features[key];
406
- if (featureConfig.callbackForwarding && featureConfig.callbackForwarding.length > 0) {
407
- installCallbackForwarding(ctr, key, featureConfig.callbackForwarding);
406
+ const optIn = supportedFeatures[key];
407
+ const authorCallbacks = optIn.callbackForwarding || [];
408
+ const consumerCallbacks = featureConfig.callbackForwarding || [];
409
+ // Union of both (author defaults + consumer additions)
410
+ const allCallbacks = [...new Set([...authorCallbacks, ...consumerCallbacks])];
411
+ if (allCallbacks.length > 0) {
412
+ installCallbackForwarding(ctr, key, allCallbacks);
408
413
  }
409
414
  }
410
415
  // 6. Install whenFeatureReady method if featuresConfig.lifecycleKeys is configured
package/assignFeatures.ts CHANGED
@@ -65,6 +65,16 @@ export interface SupportedFeatureConfig {
65
65
  * }
66
66
  */
67
67
  getSharedContext?: (instance: any) => any;
68
+
69
+ /**
70
+ * Lifecycle callbacks that this feature requires.
71
+ * Serves as the default — the consumer can add more via FeatureConfig.callbackForwarding
72
+ * but cannot remove these.
73
+ *
74
+ * Supported: 'connectedCallback', 'disconnectedCallback',
75
+ * 'attributeChangedCallback', 'adoptedCallback'
76
+ */
77
+ callbackForwarding?: string[];
68
78
  }
69
79
 
70
80
  /**
@@ -636,10 +646,15 @@ export function assignFeatures(
636
646
  // 5. Install the lazy getter on the prototype
637
647
  installFeatureGetter(ctr, key, featuresRegistry);
638
648
 
639
- // 6. Install callback forwarding if configured
649
+ // 6. Install callback forwarding if configured (merge author + consumer)
640
650
  const featureConfig = features[key];
641
- if (featureConfig.callbackForwarding && featureConfig.callbackForwarding.length > 0) {
642
- installCallbackForwarding(ctr, key, featureConfig.callbackForwarding);
651
+ const optIn = supportedFeatures[key];
652
+ const authorCallbacks = optIn.callbackForwarding || [];
653
+ const consumerCallbacks = featureConfig.callbackForwarding || [];
654
+ // Union of both (author defaults + consumer additions)
655
+ const allCallbacks = [...new Set([...authorCallbacks, ...consumerCallbacks])];
656
+ if (allCallbacks.length > 0) {
657
+ installCallbackForwarding(ctr, key, allCallbacks);
643
658
  }
644
659
  }
645
660
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assign-gingerly",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "description": "This package provides a utility function for carefully merging one object into another.",
5
5
  "homepage": "https://github.com/bahrus/assign-gingerly#readme",
6
6
  "bugs": {