Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for ReactNativeAttributePayloadFabric.js #29608

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,24 @@ function fastAddProperties(
props: Object,
validAttributes: AttributeConfiguration,
): null | Object {
let attributeConfig;
let prop;
// Flatten nested style props.
if (isArray(props)) {
for (let i = 0; i < props.length; i++) {
payload = fastAddProperties(payload, props[i], validAttributes);
}
return payload;
}

for (const propKey in props) {
prop = props[propKey];
const prop = props[propKey];

if (prop === undefined) {
continue;
}

attributeConfig = ((validAttributes[propKey]: any): AttributeConfiguration);
const attributeConfig = ((validAttributes[
propKey
]: any): AttributeConfiguration);

if (attributeConfig == null) {
continue;
Expand All @@ -477,7 +484,7 @@ function fastAddProperties(
// An atomic prop with custom processing.
newValue = attributeConfig.process(prop);
} else if (typeof attributeConfig.diff === 'function') {
// An atomic prop with custom diffing. We don't do diffing here.
// An atomic prop with custom diffing. We don't need to do diffing when adding props.
newValue = prop;
}

Expand All @@ -489,17 +496,6 @@ function fastAddProperties(
continue;
}

// Not-atomic prop that needs to be flattened. Likely it's the 'style' prop.

// It can be an array.
if (isArray(prop)) {
for (let i = 0; i < prop.length; i++) {
payload = fastAddProperties(payload, prop[i], attributeConfig);
}
continue;
}

// Or it can be an object.
payload = fastAddProperties(payload, prop, attributeConfig);
}

Expand All @@ -514,11 +510,7 @@ function addProperties(
props: Object,
validAttributes: AttributeConfiguration,
): null | Object {
if (enableAddPropertiesFastPath) {
return fastAddProperties(updatePayload, props, validAttributes);
} else {
return diffProperties(updatePayload, emptyObject, props, validAttributes);
}
return diffProperties(updatePayload, emptyObject, props, validAttributes);
}

/**
Expand All @@ -538,11 +530,11 @@ export function create(
props: Object,
validAttributes: AttributeConfiguration,
): null | Object {
return addProperties(
null, // updatePayload
props,
validAttributes,
);
if (enableAddPropertiesFastPath) {
return fastAddProperties(null, props, validAttributes);
} else {
return addProperties(null, props, validAttributes);
}
}

export function diff(
Expand Down
Loading