@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.
@@ -2326,17 +2326,15 @@ function applyPreparedKeyedRowBindingUpdates(props, instance, updates) {
2326
2326
  }
2327
2327
  }
2328
2328
  function prepareKeyedRowBindingSetUpdates(props, instances, rows) {
2329
- const preparedInstances = [];
2330
2329
  const preparedUpdates = [];
2331
2330
  for (let index = 0; index < rows.items.length; index += 1) {
2332
2331
  const instance = instances.get(rows.keys[index]);
2333
2332
  if (!instance) return void 0;
2334
2333
  const updates = prepareKeyedRowBindingUpdates(props, instance, rows.items[index], index);
2335
2334
  if (!updates) return void 0;
2336
- preparedInstances.push(instance);
2337
2335
  preparedUpdates.push(updates);
2338
2336
  }
2339
- return [preparedInstances, preparedUpdates];
2337
+ return preparedUpdates;
2340
2338
  }
2341
2339
  function keyedRowConditionalSnapshot(conditional, item, index) {
2342
2340
  const test = conditional.test(item, index);
@@ -6387,7 +6385,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6387
6385
  const conditionalChanges = [];
6388
6386
  for (index = 0; index < rows.items.length; index += 1) {
6389
6387
  const key = rows.keys[index];
6390
- const existing = preparedBindings?.[0][index] || this.instances.get(key);
6388
+ const existing = this.instances.get(key);
6391
6389
  if (!existing) return false;
6392
6390
  if (this.currentProps.hostBlocks) {
6393
6391
  const descriptor = this.currentProps.create(rows.items[index], index);
@@ -6396,7 +6394,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6396
6394
  return true;
6397
6395
  }
6398
6396
  }
6399
- const bindingUpdates = preparedBindings?.[1][index];
6397
+ const bindingUpdates = preparedBindings?.[index];
6400
6398
  if (bindingUpdates) {
6401
6399
  applyPreparedKeyedRowBindingUpdates(this.currentProps, existing, bindingUpdates);
6402
6400
  } else {
@@ -6425,19 +6423,15 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6425
6423
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
6426
6424
  return true;
6427
6425
  }
6428
- reconcileSingleRemoval(rows, afterCommit, dirtyState) {
6429
- if (this.hasReactOwnedRows() || rows.keys.length + 1 !== this.instances.size) return false;
6430
- const previousKeys = [...this.instances.keys()];
6431
- let removedIndex = 0;
6432
- while (removedIndex < rows.keys.length && previousKeys[removedIndex] === rows.keys[removedIndex]) {
6433
- removedIndex += 1;
6434
- }
6435
- for (let index = removedIndex; index < rows.keys.length; index += 1) {
6436
- if (previousKeys[index + 1] !== rows.keys[index]) return false;
6426
+ reconcileRemovals(rows, afterCommit, dirtyState) {
6427
+ if (this.hasReactOwnedRows() || rows.keys.length >= this.instances.size) return false;
6428
+ const removed = [];
6429
+ let nextIndex = 0;
6430
+ for (const [key, instance] of this.instances) {
6431
+ if (key === rows.keys[nextIndex]) nextIndex += 1;
6432
+ else removed.push(instance);
6437
6433
  }
6438
- const removedKey = previousKeys[removedIndex];
6439
- const removed = this.instances.get(removedKey);
6440
- if (!removed) return false;
6434
+ if (nextIndex !== rows.keys.length) return false;
6441
6435
  const shouldPrepareBindings = rows.items.length > 1 && this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks;
6442
6436
  const preparedBindings = shouldPrepareBindings ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows) : void 0;
6443
6437
  if (shouldPrepareBindings && !preparedBindings) {
@@ -6447,7 +6441,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6447
6441
  const conditionalChanges = [];
6448
6442
  for (let index = 0; index < rows.items.length; index += 1) {
6449
6443
  const key = rows.keys[index];
6450
- const existing = preparedBindings?.[0][index] || this.instances.get(key);
6444
+ const existing = this.instances.get(key);
6451
6445
  if (!existing) return false;
6452
6446
  if (this.currentProps.hostBlocks) {
6453
6447
  const descriptor = this.currentProps.create(rows.items[index], index);
@@ -6456,7 +6450,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6456
6450
  return true;
6457
6451
  }
6458
6452
  }
6459
- const bindingUpdates = preparedBindings?.[1][index];
6453
+ const bindingUpdates = preparedBindings?.[index];
6460
6454
  if (bindingUpdates) {
6461
6455
  applyPreparedKeyedRowBindingUpdates(this.currentProps, existing, bindingUpdates);
6462
6456
  } else {
@@ -6481,11 +6475,13 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6481
6475
  existing.item = rows.items[index];
6482
6476
  existing.index = index;
6483
6477
  }
6484
- removed.scope?.cleanup();
6485
- removed.element.remove();
6486
- this.instances.delete(removedKey);
6487
- this.eventHandlers.delete(removedKey);
6488
- this.conditionalListeners.delete(removedKey);
6478
+ for (const instance of removed) {
6479
+ instance.scope?.cleanup();
6480
+ instance.element.remove();
6481
+ this.instances.delete(instance.key);
6482
+ this.eventHandlers.delete(instance.key);
6483
+ this.conditionalListeners.delete(instance.key);
6484
+ }
6489
6485
  this.commitCurrentCollection(dirtyState);
6490
6486
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
6491
6487
  return true;
@@ -6534,9 +6530,14 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6534
6530
  return;
6535
6531
  }
6536
6532
  if (this.reconcileStableRows(rows, afterCommit, dirtyState)) return;
6537
- if (this.reconcileSingleRemoval(rows, afterCommit, dirtyState)) return;
6533
+ if (this.reconcileRemovals(rows, afterCommit, dirtyState)) return;
6538
6534
  const nextKeys = new Set(rows.keys);
6539
6535
  const hasSurvivingRows = rows.keys.some((key) => this.instances.has(key));
6536
+ 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;
6537
+ if (preparedBindings === void 0) {
6538
+ this.activateFallback(afterCommit);
6539
+ return;
6540
+ }
6540
6541
  const oldIndices = /* @__PURE__ */ new Map();
6541
6542
  if (hasSurvivingRows) {
6542
6543
  [...this.instances].forEach(([key], index) => oldIndices.set(key, index));
@@ -6561,7 +6562,15 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6561
6562
  return;
6562
6563
  }
6563
6564
  }
6564
- applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6565
+ if (preparedBindings) {
6566
+ applyPreparedKeyedRowBindingUpdates(
6567
+ this.currentProps,
6568
+ existing,
6569
+ preparedBindings[index]
6570
+ );
6571
+ } else {
6572
+ applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6573
+ }
6565
6574
  const conditionalValues = this.readConditionalValues(
6566
6575
  this.currentProps,
6567
6576
  rows.items[index],