@farm.js/react 0.1.0-beta.14 → 0.1.0-beta.15

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.
@@ -2302,16 +2302,21 @@ function commitKeyedRowBinding(binding, instance, bindingIndex, value, target) {
2302
2302
  updateAttribute(target, binding.name, value);
2303
2303
  }
2304
2304
  }
2305
+ function prepareKeyedRowBindingUpdate(props, instance, item, index, bindingIndex) {
2306
+ const binding = props.bindings[bindingIndex];
2307
+ const rawValue = binding.read(item, index);
2308
+ const value = normalizedKeyedRowBindingValue(binding, rawValue);
2309
+ if (Object.is(instance.values[bindingIndex], value)) return null;
2310
+ const target = findCompilerHostTarget(instance.element, binding.path);
2311
+ if (!target || binding.kind !== "text" && !binding.name) return void 0;
2312
+ return [bindingIndex, target, value];
2313
+ }
2305
2314
  function prepareKeyedRowBindingUpdates(props, instance, item, index) {
2306
2315
  const updates = [];
2307
2316
  for (let bindingIndex = 0; bindingIndex < props.bindings.length; bindingIndex += 1) {
2308
- const binding = props.bindings[bindingIndex];
2309
- const rawValue = binding.read(item, index);
2310
- const value = normalizedKeyedRowBindingValue(binding, rawValue);
2311
- if (Object.is(instance.values[bindingIndex], value)) continue;
2312
- const target = findCompilerHostTarget(instance.element, binding.path);
2313
- if (!target || binding.kind !== "text" && !binding.name) return void 0;
2314
- updates.push([bindingIndex, target, value]);
2317
+ const update = prepareKeyedRowBindingUpdate(props, instance, item, index, bindingIndex);
2318
+ if (update === void 0) return void 0;
2319
+ if (update) updates.push(update);
2315
2320
  }
2316
2321
  return updates;
2317
2322
  }
@@ -2320,6 +2325,19 @@ function applyPreparedKeyedRowBindingUpdates(props, instance, updates) {
2320
2325
  commitKeyedRowBinding(props.bindings[bindingIndex], instance, bindingIndex, value, target);
2321
2326
  }
2322
2327
  }
2328
+ function prepareKeyedRowBindingSetUpdates(props, instances, rows) {
2329
+ const preparedInstances = [];
2330
+ const preparedUpdates = [];
2331
+ for (let index = 0; index < rows.items.length; index += 1) {
2332
+ const instance = instances.get(rows.keys[index]);
2333
+ if (!instance) return void 0;
2334
+ const updates = prepareKeyedRowBindingUpdates(props, instance, rows.items[index], index);
2335
+ if (!updates) return void 0;
2336
+ preparedInstances.push(instance);
2337
+ preparedUpdates.push(updates);
2338
+ }
2339
+ return [preparedInstances, preparedUpdates];
2340
+ }
2323
2341
  function keyedRowConditionalSnapshot(conditional, item, index) {
2324
2342
  const test = conditional.test(item, index);
2325
2343
  if (conditional.logical && !test) {
@@ -6252,6 +6270,7 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6252
6270
  nextMapLookupTargets.set(bindingIndex, snapshot);
6253
6271
  }
6254
6272
  }
6273
+ let preparedBindingUpdates;
6255
6274
  for (const bindingIndex of affectedBindingIndices) {
6256
6275
  const binding = this.currentProps.bindings[bindingIndex];
6257
6276
  const identityTarget = binding.identityTarget;
@@ -6272,52 +6291,32 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6272
6291
  const canTargetMapLookup = Boolean(
6273
6292
  mapLookupTarget && binding.dependencies?.length === 1 && binding.dependencies[0] === mapLookupTarget.dependency && dirtyState.has(mapLookupTarget.dependency) && previousMapLookupTarget?.eligible && nextMapLookupTarget?.eligible
6274
6293
  );
6294
+ let selectedKeys;
6295
+ let selectedCount;
6275
6296
  if (canTargetMapLookup && previousMapLookupTarget && nextMapLookupTarget) {
6276
6297
  const keys = keyedMapLookupChangedKeys(previousMapLookupTarget, nextMapLookupTarget);
6277
- for (const key of keys) {
6278
- const instance = this.instances.get(key);
6279
- if (instance) {
6280
- applyKeyedRowBinding(
6281
- this.currentProps,
6282
- instance,
6283
- instance.item,
6284
- instance.index,
6285
- bindingIndex
6286
- );
6287
- }
6288
- }
6298
+ selectedKeys = keys;
6299
+ selectedCount = keys.size;
6289
6300
  } else if (canTargetMembership && previousMembershipTarget && nextMembershipTarget) {
6290
6301
  const keys = keyedMembershipChangedKeys(previousMembershipTarget, nextMembershipTarget);
6291
- for (const key of keys) {
6292
- const instance = this.instances.get(key);
6293
- if (instance) {
6294
- applyKeyedRowBinding(
6295
- this.currentProps,
6296
- instance,
6297
- instance.item,
6298
- instance.index,
6299
- bindingIndex
6300
- );
6301
- }
6302
- }
6302
+ selectedKeys = keys;
6303
+ selectedCount = keys.size;
6303
6304
  } else if (canTargetIdentity && previousIdentityTarget && nextIdentityTarget) {
6304
6305
  const keys = /* @__PURE__ */ new Set();
6305
6306
  if (previousIdentityTarget.key !== void 0) keys.add(previousIdentityTarget.key);
6306
6307
  if (nextIdentityTarget.key !== void 0) keys.add(nextIdentityTarget.key);
6307
- for (const key of keys) {
6308
- const instance = this.instances.get(key);
6309
- if (instance) {
6310
- applyKeyedRowBinding(
6311
- this.currentProps,
6312
- instance,
6313
- instance.item,
6314
- instance.index,
6315
- bindingIndex
6316
- );
6317
- }
6318
- }
6308
+ selectedKeys = keys;
6309
+ selectedCount = keys.size;
6319
6310
  } else {
6320
- for (const instance of this.instances.values()) {
6311
+ selectedKeys = this.instances.keys();
6312
+ selectedCount = this.instances.size;
6313
+ }
6314
+ const prepare = affectedBindingIndices.length > 1 || selectedCount > 1;
6315
+ if (prepare) preparedBindingUpdates || (preparedBindingUpdates = []);
6316
+ for (const key of selectedKeys) {
6317
+ const instance = this.instances.get(key);
6318
+ if (!instance) continue;
6319
+ if (!prepare) {
6321
6320
  applyKeyedRowBinding(
6322
6321
  this.currentProps,
6323
6322
  instance,
@@ -6325,8 +6324,37 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6325
6324
  instance.index,
6326
6325
  bindingIndex
6327
6326
  );
6327
+ continue;
6328
6328
  }
6329
+ const update = prepareKeyedRowBindingUpdate(
6330
+ this.currentProps,
6331
+ instance,
6332
+ instance.item,
6333
+ instance.index,
6334
+ bindingIndex
6335
+ );
6336
+ if (update === void 0) {
6337
+ this.activateFallback(afterCommit);
6338
+ return true;
6339
+ }
6340
+ if (update) preparedBindingUpdates.push([instance, update]);
6329
6341
  }
6342
+ }
6343
+ if (preparedBindingUpdates) {
6344
+ for (const [instance, [bindingIndex, target, value]] of preparedBindingUpdates) {
6345
+ commitKeyedRowBinding(
6346
+ this.currentProps.bindings[bindingIndex],
6347
+ instance,
6348
+ bindingIndex,
6349
+ value,
6350
+ target
6351
+ );
6352
+ }
6353
+ }
6354
+ for (const bindingIndex of affectedBindingIndices) {
6355
+ const nextIdentityTarget = nextIdentityTargets.get(bindingIndex);
6356
+ const nextMembershipTarget = nextMembershipTargets.get(bindingIndex);
6357
+ const nextMapLookupTarget = nextMapLookupTargets.get(bindingIndex);
6330
6358
  if (nextIdentityTarget) this.identityTargets.set(bindingIndex, nextIdentityTarget);
6331
6359
  else this.identityTargets.delete(bindingIndex);
6332
6360
  if (nextMembershipTarget) {
@@ -6350,10 +6378,16 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6350
6378
  if (rows.keys[index] !== key) return false;
6351
6379
  index += 1;
6352
6380
  }
6381
+ const shouldPrepareBindings = rows.items.length > 1 && this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks;
6382
+ const preparedBindings = shouldPrepareBindings ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows) : void 0;
6383
+ if (shouldPrepareBindings && !preparedBindings) {
6384
+ this.activateFallback(afterCommit);
6385
+ return true;
6386
+ }
6353
6387
  const conditionalChanges = [];
6354
6388
  for (index = 0; index < rows.items.length; index += 1) {
6355
6389
  const key = rows.keys[index];
6356
- const existing = this.instances.get(key);
6390
+ const existing = preparedBindings?.[0][index] || this.instances.get(key);
6357
6391
  if (!existing) return false;
6358
6392
  if (this.currentProps.hostBlocks) {
6359
6393
  const descriptor = this.currentProps.create(rows.items[index], index);
@@ -6362,7 +6396,12 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6362
6396
  return true;
6363
6397
  }
6364
6398
  }
6365
- applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6399
+ const bindingUpdates = preparedBindings?.[1][index];
6400
+ if (bindingUpdates) {
6401
+ applyPreparedKeyedRowBindingUpdates(this.currentProps, existing, bindingUpdates);
6402
+ } else {
6403
+ applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6404
+ }
6366
6405
  const conditionalValues = this.readConditionalValues(
6367
6406
  this.currentProps,
6368
6407
  rows.items[index],
@@ -6399,10 +6438,16 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6399
6438
  const removedKey = previousKeys[removedIndex];
6400
6439
  const removed = this.instances.get(removedKey);
6401
6440
  if (!removed) return false;
6441
+ const shouldPrepareBindings = rows.items.length > 1 && this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks;
6442
+ const preparedBindings = shouldPrepareBindings ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows) : void 0;
6443
+ if (shouldPrepareBindings && !preparedBindings) {
6444
+ this.activateFallback(afterCommit);
6445
+ return true;
6446
+ }
6402
6447
  const conditionalChanges = [];
6403
6448
  for (let index = 0; index < rows.items.length; index += 1) {
6404
6449
  const key = rows.keys[index];
6405
- const existing = this.instances.get(key);
6450
+ const existing = preparedBindings?.[0][index] || this.instances.get(key);
6406
6451
  if (!existing) return false;
6407
6452
  if (this.currentProps.hostBlocks) {
6408
6453
  const descriptor = this.currentProps.create(rows.items[index], index);
@@ -6411,7 +6456,12 @@ function createKeyedRowsBlockComponent(owner, options = {}) {
6411
6456
  return true;
6412
6457
  }
6413
6458
  }
6414
- applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6459
+ const bindingUpdates = preparedBindings?.[1][index];
6460
+ if (bindingUpdates) {
6461
+ applyPreparedKeyedRowBindingUpdates(this.currentProps, existing, bindingUpdates);
6462
+ } else {
6463
+ applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6464
+ }
6415
6465
  const conditionalValues = this.readConditionalValues(
6416
6466
  this.currentProps,
6417
6467
  rows.items[index],