@farm.js/react 0.1.0-beta.16 → 0.1.0-beta.18

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.
@@ -2332,17 +2332,15 @@ function applyPreparedKeyedRowBindingUpdates(props, instance, updates) {
2332
2332
  }
2333
2333
  }
2334
2334
  function prepareKeyedRowBindingSetUpdates(props, instances, rows) {
2335
- const preparedInstances = [];
2336
2335
  const preparedUpdates = [];
2337
2336
  for (let index = 0; index < rows.items.length; index += 1) {
2338
2337
  const instance = instances.get(rows.keys[index]);
2339
2338
  if (!instance) return void 0;
2340
2339
  const updates = prepareKeyedRowBindingUpdates(props, instance, rows.items[index], index);
2341
2340
  if (!updates) return void 0;
2342
- preparedInstances.push(instance);
2343
2341
  preparedUpdates.push(updates);
2344
2342
  }
2345
- return [preparedInstances, preparedUpdates];
2343
+ return preparedUpdates;
2346
2344
  }
2347
2345
  function keyedRowConditionalSnapshot(conditional, item, index) {
2348
2346
  const test = conditional.test(item, index);
@@ -6393,7 +6391,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6393
6391
  const conditionalChanges = [];
6394
6392
  for (index = 0; index < rows.items.length; index += 1) {
6395
6393
  const key = rows.keys[index];
6396
- const existing = preparedBindings?.[0][index] || this.instances.get(key);
6394
+ const existing = this.instances.get(key);
6397
6395
  if (!existing) return false;
6398
6396
  if (this.currentProps.hostBlocks) {
6399
6397
  const descriptor = this.currentProps.create(rows.items[index], index);
@@ -6402,7 +6400,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6402
6400
  return true;
6403
6401
  }
6404
6402
  }
6405
- const bindingUpdates = preparedBindings?.[1][index];
6403
+ const bindingUpdates = preparedBindings?.[index];
6406
6404
  if (bindingUpdates) {
6407
6405
  applyPreparedKeyedRowBindingUpdates(this.currentProps, existing, bindingUpdates);
6408
6406
  } else {
@@ -6431,20 +6429,22 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6431
6429
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
6432
6430
  return true;
6433
6431
  }
6434
- reconcileSingleRemoval(rows, afterCommit, dirtyState) {
6435
- if (this.hasReactOwnedRows() || rows.keys.length + 1 !== this.instances.size) return false;
6436
- const previousKeys = [...this.instances.keys()];
6437
- let removedIndex = 0;
6438
- while (removedIndex < rows.keys.length && previousKeys[removedIndex] === rows.keys[removedIndex]) {
6439
- removedIndex += 1;
6432
+ reconcileRemovals(rows, afterCommit, dirtyState) {
6433
+ if (this.hasReactOwnedRows() || rows.keys.length >= this.instances.size) return false;
6434
+ const removed = [];
6435
+ let nextIndex = 0;
6436
+ for (const [key, instance] of this.instances) {
6437
+ if (key === rows.keys[nextIndex]) nextIndex += 1;
6438
+ else removed.push(instance);
6440
6439
  }
6441
- for (let index = removedIndex; index < rows.keys.length; index += 1) {
6442
- if (previousKeys[index + 1] !== rows.keys[index]) return false;
6440
+ if (nextIndex !== rows.keys.length) return false;
6441
+ const shouldPrepareBindings = this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks;
6442
+ if (shouldPrepareBindings && rows.items.length === 1 && this.currentProps.bindings.some(
6443
+ (binding) => !findCompilerHostTarget(this.instances.get(rows.keys[0]).element, binding.path)
6444
+ )) {
6445
+ this.activateFallback(afterCommit);
6446
+ return true;
6443
6447
  }
6444
- const removedKey = previousKeys[removedIndex];
6445
- const removed = this.instances.get(removedKey);
6446
- if (!removed) return false;
6447
- const shouldPrepareBindings = rows.items.length > 1 && this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks;
6448
6448
  const preparedBindings = shouldPrepareBindings ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows) : void 0;
6449
6449
  if (shouldPrepareBindings && !preparedBindings) {
6450
6450
  this.activateFallback(afterCommit);
@@ -6453,7 +6453,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6453
6453
  const conditionalChanges = [];
6454
6454
  for (let index = 0; index < rows.items.length; index += 1) {
6455
6455
  const key = rows.keys[index];
6456
- const existing = preparedBindings?.[0][index] || this.instances.get(key);
6456
+ const existing = this.instances.get(key);
6457
6457
  if (!existing) return false;
6458
6458
  if (this.currentProps.hostBlocks) {
6459
6459
  const descriptor = this.currentProps.create(rows.items[index], index);
@@ -6462,7 +6462,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6462
6462
  return true;
6463
6463
  }
6464
6464
  }
6465
- const bindingUpdates = preparedBindings?.[1][index];
6465
+ const bindingUpdates = preparedBindings?.[index];
6466
6466
  if (bindingUpdates) {
6467
6467
  applyPreparedKeyedRowBindingUpdates(this.currentProps, existing, bindingUpdates);
6468
6468
  } else {
@@ -6487,11 +6487,13 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6487
6487
  existing.item = rows.items[index];
6488
6488
  existing.index = index;
6489
6489
  }
6490
- removed.scope?.cleanup();
6491
- removed.element.remove();
6492
- this.instances.delete(removedKey);
6493
- this.eventHandlers.delete(removedKey);
6494
- this.conditionalListeners.delete(removedKey);
6490
+ for (const instance of removed) {
6491
+ instance.scope?.cleanup();
6492
+ instance.element.remove();
6493
+ this.instances.delete(instance.key);
6494
+ this.eventHandlers.delete(instance.key);
6495
+ this.conditionalListeners.delete(instance.key);
6496
+ }
6495
6497
  this.commitCurrentCollection(dirtyState);
6496
6498
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
6497
6499
  return true;
@@ -6540,9 +6542,14 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6540
6542
  return;
6541
6543
  }
6542
6544
  if (this.reconcileStableRows(rows, afterCommit, dirtyState)) return;
6543
- if (this.reconcileSingleRemoval(rows, afterCommit, dirtyState)) return;
6545
+ if (this.reconcileRemovals(rows, afterCommit, dirtyState)) return;
6544
6546
  const nextKeys = new Set(rows.keys);
6545
6547
  const hasSurvivingRows = rows.keys.some((key) => this.instances.has(key));
6548
+ const preparedBindings = nextKeys.size < this.instances.size && this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks && rows.keys.every((key) => this.instances.has(key)) ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows) : null;
6549
+ if (preparedBindings === void 0) {
6550
+ this.activateFallback(afterCommit);
6551
+ return;
6552
+ }
6546
6553
  const oldIndices = /* @__PURE__ */ new Map();
6547
6554
  if (hasSurvivingRows) {
6548
6555
  [...this.instances].forEach(([key], index) => oldIndices.set(key, index));
@@ -6567,7 +6574,15 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6567
6574
  return;
6568
6575
  }
6569
6576
  }
6570
- applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6577
+ if (preparedBindings) {
6578
+ applyPreparedKeyedRowBindingUpdates(
6579
+ this.currentProps,
6580
+ existing,
6581
+ preparedBindings[index]
6582
+ );
6583
+ } else {
6584
+ applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6585
+ }
6571
6586
  const conditionalValues = this.readConditionalValues(
6572
6587
  this.currentProps,
6573
6588
  rows.items[index],