@jinntec/fore 2.9.0 → 3.0.1

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.
@@ -50,6 +50,8 @@ export class FxRepeatitem extends withDraggability(UIElement, true) {
50
50
  `;
51
51
  this.getOwnerForm().registerLazyElement(this);
52
52
 
53
+ // Keep ref as a *property only* so repeatitem does not become the nearest [ref] for its children.
54
+ // Its children already get their context from the repeatitem via getInScopeContext().
53
55
  this.ref = `${this.parentNode.ref}`;
54
56
 
55
57
  this.tabindex = 0;
@@ -58,7 +60,7 @@ export class FxRepeatitem extends withDraggability(UIElement, true) {
58
60
  disconnectedCallback() {
59
61
  super.disconnectedCallback();
60
62
  this.removeEventListener('click', this._dispatchIndexChange);
61
- this.removeEventListener('focusin', this._handleFocus);
63
+ this.removeEventListener('focusin', this._dispatchIndexChange);
62
64
  }
63
65
 
64
66
  init() {
@@ -96,6 +98,19 @@ export class FxRepeatitem extends withDraggability(UIElement, true) {
96
98
  this.getOwnerForm().refresh();
97
99
  }
98
100
 
101
+ update(_modelItem) {
102
+ // Repeatitems must refresh when their ModelItem facets (e.g. relevant) change,
103
+ // but they should NOT have a `ref` attribute (that would change inscope context resolution).
104
+ const fore = this.getOwnerForm();
105
+ if (!fore) return;
106
+
107
+ if (fore.isRefreshPhase) {
108
+ fore.addToBatchedNotifications(this);
109
+ } else {
110
+ this.refresh();
111
+ }
112
+ }
113
+
99
114
  async refresh(force = false) {
100
115
  // this.modelItem = this.getModelItem();
101
116
  this.attachObserver();
@@ -199,12 +199,15 @@ export class RepeatBase extends withDraggability(UIElement, false) {
199
199
 
200
200
  // Generate the parent `modelItem` for the new repeat item
201
201
  this.opNum++;
202
- const parentModelItem = FxBind.createModelItem(this.ref, node, this, this.opNum);
202
+ let parentModelItem = FxBind.createModelItem(this.ref, node, this, this.opNum);
203
+ // IMPORTANT: registerModelItem may return an existing canonical ModelItem for the same path.
204
+ // Always keep using the returned instance to avoid "ghost" ModelItems that still notify.
205
+ parentModelItem = this.getModel().registerModelItem(parentModelItem);
203
206
  newRepeatItem.modelItem = parentModelItem;
204
207
 
205
208
  this.setIndex(insertionIndex);
206
209
 
207
- this.getModel().registerModelItem(parentModelItem);
210
+ // parentModelItem already registered above
208
211
 
209
212
  // Step 5: Create modelItems recursively for child elements
210
213
  this._createModelItemsRecursively(newRepeatItem, parentModelItem);
@@ -214,7 +217,6 @@ export class RepeatBase extends withDraggability(UIElement, false) {
214
217
 
215
218
  this.getOwnerForm().addToBatchedNotifications(newRepeatItem);
216
219
  }
217
-
218
220
  /**
219
221
  * @abstract
220
222
  *
@@ -475,7 +477,9 @@ export class RepeatBase extends withDraggability(UIElement, false) {
475
477
  // Create a ModelItem only for the final node; children never get their own opNum
476
478
  modelItem = FxBind.createModelItem(ref, node, child, null);
477
479
  modelItem.parentModelItem = parentModelItem;
478
- this.getModel().registerModelItem(modelItem);
480
+ // IMPORTANT: keep using the canonical instance returned by registerModelItem.
481
+ // Otherwise a throwaway ModelItem can leak into observer graphs and be notified.
482
+ modelItem = this.getModel().registerModelItem(modelItem);
479
483
  }
480
484
 
481
485
  // Always apply Dewey rewrite (handles both $inst and instance('inst') forms)
@@ -217,7 +217,6 @@ export const withDraggability = (superclass, isAlsoDraggable) =>
217
217
  }
218
218
 
219
219
  // Note: full refresh needed since multiple model items may be affected.
220
- // TODO: Leverage the changedPaths trick
221
220
  this.getOwnerForm().getModel().updateModel();
222
221
  this.getOwnerForm().refresh(true);
223
222
  }