Skip to content

Commit 51dd096

Browse files
authored
Add tests for ReactNativeAttributePayloadFabric.js (#29608)
## Summary This PR add tests for `ReactNativeAttributePayloadFabric.js`. It introduces `ReactNativeAttributePayloadFabric-test.internal.js`, which is a copy-paste of `ReactNativeAttributePayload-test.internal.js`. On top of that, there is a bunch of new test cases for the `ReactNativeAttributePayloadFabric.create` function. ## How did you test this change? ``` yarn test packages/react-native-renderer ```
1 parent c2b45ef commit 51dd096

File tree

2 files changed

+464
-26
lines changed

2 files changed

+464
-26
lines changed

packages/react-native-renderer/src/ReactNativeAttributePayloadFabric.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -449,17 +449,24 @@ function fastAddProperties(
449449
props: Object,
450450
validAttributes: AttributeConfiguration,
451451
): null | Object {
452-
let attributeConfig;
453-
let prop;
452+
// Flatten nested style props.
453+
if (isArray(props)) {
454+
for (let i = 0; i < props.length; i++) {
455+
payload = fastAddProperties(payload, props[i], validAttributes);
456+
}
457+
return payload;
458+
}
454459

455460
for (const propKey in props) {
456-
prop = props[propKey];
461+
const prop = props[propKey];
457462

458463
if (prop === undefined) {
459464
continue;
460465
}
461466

462-
attributeConfig = ((validAttributes[propKey]: any): AttributeConfiguration);
467+
const attributeConfig = ((validAttributes[
468+
propKey
469+
]: any): AttributeConfiguration);
463470

464471
if (attributeConfig == null) {
465472
continue;
@@ -477,7 +484,7 @@ function fastAddProperties(
477484
// An atomic prop with custom processing.
478485
newValue = attributeConfig.process(prop);
479486
} else if (typeof attributeConfig.diff === 'function') {
480-
// An atomic prop with custom diffing. We don't do diffing here.
487+
// An atomic prop with custom diffing. We don't need to do diffing when adding props.
481488
newValue = prop;
482489
}
483490

@@ -489,17 +496,6 @@ function fastAddProperties(
489496
continue;
490497
}
491498

492-
// Not-atomic prop that needs to be flattened. Likely it's the 'style' prop.
493-
494-
// It can be an array.
495-
if (isArray(prop)) {
496-
for (let i = 0; i < prop.length; i++) {
497-
payload = fastAddProperties(payload, prop[i], attributeConfig);
498-
}
499-
continue;
500-
}
501-
502-
// Or it can be an object.
503499
payload = fastAddProperties(payload, prop, attributeConfig);
504500
}
505501

@@ -514,11 +510,7 @@ function addProperties(
514510
props: Object,
515511
validAttributes: AttributeConfiguration,
516512
): null | Object {
517-
if (enableAddPropertiesFastPath) {
518-
return fastAddProperties(updatePayload, props, validAttributes);
519-
} else {
520-
return diffProperties(updatePayload, emptyObject, props, validAttributes);
521-
}
513+
return diffProperties(updatePayload, emptyObject, props, validAttributes);
522514
}
523515

524516
/**
@@ -538,11 +530,11 @@ export function create(
538530
props: Object,
539531
validAttributes: AttributeConfiguration,
540532
): null | Object {
541-
return addProperties(
542-
null, // updatePayload
543-
props,
544-
validAttributes,
545-
);
533+
if (enableAddPropertiesFastPath) {
534+
return fastAddProperties(null, props, validAttributes);
535+
} else {
536+
return addProperties(null, props, validAttributes);
537+
}
546538
}
547539

548540
export function diff(

0 commit comments

Comments
 (0)