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

Create Fabric-specific version of ReactNativeAttributesPayload #28841

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,7 +12,7 @@ import type {
TouchedViewDataAtPoint,
ViewConfig,
} from './ReactNativeTypes';
import {create, diff} from './ReactNativeAttributePayload';
import {create, diff} from './ReactNativeAttributePayloadFabric';
import {dispatchEvent} from './ReactFabricEventEmitter';
import {
NoEventPriority,
Expand Down
70 changes: 2 additions & 68 deletions packages/react-native-renderer/src/ReactNativeAttributePayload.js
Expand Up @@ -15,7 +15,6 @@ import {
import isArray from 'shared/isArray';

import {enableEarlyReturnForPropDiffing} from 'shared/ReactFeatureFlags';
import {enableAddPropertiesFastPath} from 'shared/ReactFeatureFlags';

import type {AttributeConfiguration} from './ReactNativeTypes';

Expand Down Expand Up @@ -445,68 +444,6 @@ function diffProperties(
return updatePayload;
}

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

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

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

attributeConfig = validAttributes[propKey];

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

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

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

if (typeof attributeConfig.process === 'function') {
if (!updatePayload) {
updatePayload = ({}: {[string]: $FlowFixMe});
}
updatePayload[propKey] = attributeConfig.process(nextProp);
continue;
}

if (isArray(nextProp)) {
for (let i = 0; i < nextProp.length; i++) {
updatePayload = fastAddProperties(
updatePayload,
nextProp[i],
((attributeConfig: any): AttributeConfiguration),
);
}
continue;
}

updatePayload = fastAddProperties(
updatePayload,
nextProp,
((attributeConfig: any): AttributeConfiguration),
);
}

return updatePayload;
}

/**
* addProperties adds all the valid props to the payload after being processed.
*/
Expand All @@ -515,11 +452,8 @@ function addProperties(
props: Object,
validAttributes: AttributeConfiguration,
): null | Object {
if (enableAddPropertiesFastPath) {
return fastAddProperties(updatePayload, props, validAttributes);
} else {
return diffProperties(updatePayload, emptyObject, props, validAttributes);
}
// TODO: Fast path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this TODO if we're only going to do so in ReactNativeAttributePayloadFabric. I don't believe we should be making any other changes to Paper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just how the code looked before I added fastAddProperties.

return diffProperties(updatePayload, emptyObject, props, validAttributes);
}

/**
Expand Down