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

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,19 +6429,15 @@ 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;
6440
- }
6441
- for (let index = removedIndex; index < rows.keys.length; index += 1) {
6442
- if (previousKeys[index + 1] !== rows.keys[index]) return false;
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);
6443
6439
  }
6444
- const removedKey = previousKeys[removedIndex];
6445
- const removed = this.instances.get(removedKey);
6446
- if (!removed) return false;
6440
+ if (nextIndex !== rows.keys.length) return false;
6447
6441
  const shouldPrepareBindings = rows.items.length > 1 && this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks;
6448
6442
  const preparedBindings = shouldPrepareBindings ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows) : void 0;
6449
6443
  if (shouldPrepareBindings && !preparedBindings) {
@@ -6453,7 +6447,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6453
6447
  const conditionalChanges = [];
6454
6448
  for (let index = 0; index < rows.items.length; index += 1) {
6455
6449
  const key = rows.keys[index];
6456
- const existing = preparedBindings?.[0][index] || this.instances.get(key);
6450
+ const existing = this.instances.get(key);
6457
6451
  if (!existing) return false;
6458
6452
  if (this.currentProps.hostBlocks) {
6459
6453
  const descriptor = this.currentProps.create(rows.items[index], index);
@@ -6462,7 +6456,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6462
6456
  return true;
6463
6457
  }
6464
6458
  }
6465
- const bindingUpdates = preparedBindings?.[1][index];
6459
+ const bindingUpdates = preparedBindings?.[index];
6466
6460
  if (bindingUpdates) {
6467
6461
  applyPreparedKeyedRowBindingUpdates(this.currentProps, existing, bindingUpdates);
6468
6462
  } else {
@@ -6487,11 +6481,13 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6487
6481
  existing.item = rows.items[index];
6488
6482
  existing.index = index;
6489
6483
  }
6490
- removed.scope?.cleanup();
6491
- removed.element.remove();
6492
- this.instances.delete(removedKey);
6493
- this.eventHandlers.delete(removedKey);
6494
- this.conditionalListeners.delete(removedKey);
6484
+ for (const instance of removed) {
6485
+ instance.scope?.cleanup();
6486
+ instance.element.remove();
6487
+ this.instances.delete(instance.key);
6488
+ this.eventHandlers.delete(instance.key);
6489
+ this.conditionalListeners.delete(instance.key);
6490
+ }
6495
6491
  this.commitCurrentCollection(dirtyState);
6496
6492
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
6497
6493
  return true;
@@ -6540,9 +6536,14 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6540
6536
  return;
6541
6537
  }
6542
6538
  if (this.reconcileStableRows(rows, afterCommit, dirtyState)) return;
6543
- if (this.reconcileSingleRemoval(rows, afterCommit, dirtyState)) return;
6539
+ if (this.reconcileRemovals(rows, afterCommit, dirtyState)) return;
6544
6540
  const nextKeys = new Set(rows.keys);
6545
6541
  const hasSurvivingRows = rows.keys.some((key) => this.instances.has(key));
6542
+ 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;
6543
+ if (preparedBindings === void 0) {
6544
+ this.activateFallback(afterCommit);
6545
+ return;
6546
+ }
6546
6547
  const oldIndices = /* @__PURE__ */ new Map();
6547
6548
  if (hasSurvivingRows) {
6548
6549
  [...this.instances].forEach(([key], index) => oldIndices.set(key, index));
@@ -6567,7 +6568,15 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6567
6568
  return;
6568
6569
  }
6569
6570
  }
6570
- applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6571
+ if (preparedBindings) {
6572
+ applyPreparedKeyedRowBindingUpdates(
6573
+ this.currentProps,
6574
+ existing,
6575
+ preparedBindings[index]
6576
+ );
6577
+ } else {
6578
+ applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6579
+ }
6571
6580
  const conditionalValues = this.readConditionalValues(
6572
6581
  this.currentProps,
6573
6582
  rows.items[index],