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

Clean up fastAddProperties and make it more correct #29015

Merged
merged 1 commit into from
May 8, 2024
Merged
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 @@ -446,65 +446,65 @@ function diffProperties(
}

function fastAddProperties(
updatePayload: null | Object,
nextProps: Object,
payload: null | Object,
props: Object,
validAttributes: AttributeConfiguration,
): null | Object {
let attributeConfig;
let nextProp;
let prop;

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

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

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

if (attributeConfig === undefined) {
if (attributeConfig == null) {
continue;
}

if (typeof nextProp === 'function') {
nextProp = (true: any);
let newValue;

if (typeof prop === 'function') {
// A function prop. It represents an event handler. Pass it to native as 'true'.
newValue = true;
} else if (typeof attributeConfig !== 'object') {
// An atomic prop. Doesn't need to be flattened.
newValue = prop;
} else if (typeof attributeConfig.process === 'function') {
// 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.
newValue = prop;
}

if (typeof attributeConfig !== 'object') {
if (!updatePayload) {
updatePayload = ({}: {[string]: $FlowFixMe});
if (newValue !== undefined) {
if (!payload) {
payload = ({}: {[string]: $FlowFixMe});
}
updatePayload[propKey] = nextProp;
payload[propKey] = newValue;
continue;
}

if (typeof attributeConfig.process === 'function') {
if (!updatePayload) {
updatePayload = ({}: {[string]: $FlowFixMe});
}
updatePayload[propKey] = attributeConfig.process(nextProp);
continue;
}
// Not-atomic prop that needs to be flattened. Likely it's the 'style' prop.

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

updatePayload = fastAddProperties(
updatePayload,
nextProp,
((attributeConfig: any): AttributeConfiguration),
);
// Or it can be an object.
payload = fastAddProperties(payload, prop, attributeConfig);
}

return updatePayload;
return payload;
}

/**
Expand Down