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