Skip to content

Commit

Permalink
Make lefthandObjectDiff private to verifyComponentAttributeEquivalence
Browse files Browse the repository at this point in the history
Summary:
## Rationale
verifyComponentAttributeEquivalence is the legacy check for making sure that Static ViewConfigs match Native ViewConfigs. Eventually, we should just delete this module/check from the codebase.

## Changes
This diff migrates the RNHostComponentViewConfig differences screen to display the ViewConfig differences using the new StaticViewConfigValidator validation result vs the legacy validator's lefthandObjectDiff method.

## Benefits:
- Now, **all the diffing logic** on this route uses the new StaticViewConfigValidator.
- This takes us one step closer towards deleting verifyComponentAttributeEquivalence
- StaticViewConfigValidator [supports ignoring ViewConfig properties](https://fburl.com/code/2it5r7py). Now, the RNHostComponentViewConfig respects these ignores.

Changelog: [Internal]

Reviewed By: p-sun

Differential Revision: D34017602

fbshipit-source-id: 3ad909adcbb95b932a269dd55dd5445834a9cfd4
  • Loading branch information
RSNara authored and facebook-github-bot committed Feb 5, 2022
1 parent 7cc7e66 commit b8a2f34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions Libraries/NativeComponent/StaticViewConfigValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import getNativeComponentAttributes from '../ReactNative/getNativeComponentAttri
import {createViewConfig} from './ViewConfig';
import {isIgnored} from './ViewConfigIgnore';

type Difference =
export type Difference =
| {
type: 'missing',
path: Array<string>,
Expand All @@ -33,7 +33,7 @@ type Difference =
staticValue: mixed,
};

type ValidationResult = ValidResult | InvalidResult;
export type ValidationResult = ValidResult | InvalidResult;
type ValidResult = {
type: 'valid',
};
Expand All @@ -42,19 +42,15 @@ type InvalidResult = {
differences: Array<Difference>,
};

type ViewConfigValidationResult = {
// e.g. require('MyNativeComponent') where MyNativeComponent.js exports a HostComponent
type JSModule = $FlowFixMe;

export function validateStaticViewConfigs(nativeComponent: JSModule): {
componentName: string,
nativeViewConfig?: ?ViewConfig,
staticViewConfig?: ?ViewConfig,
validationResult?: ?ValidationResult,
};

// e.g. require('MyNativeComponent') where MyNativeComponent.js exports a HostComponent
type JSModule = $FlowFixMe;

export function validateStaticViewConfigs(
nativeComponent: JSModule,
): ViewConfigValidationResult {
} {
const nativeViewConfig = getNativeComponentAttributes(
nativeComponent.default || nativeComponent,
);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Utilities/verifyComponentAttributeEquivalence.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function verifyComponentAttributeEquivalence(

// Return the different key-value pairs of the right object, by iterating through the keys in the left object
// Note it won't return a difference where a key is missing in the left but exists the right.
export function lefthandObjectDiff(leftObj: Object, rightObj: Object): Object {
function lefthandObjectDiff(leftObj: Object, rightObj: Object): Object {
const differentKeys = {};

function compare(leftItem: any, rightItem: any, key: string) {
Expand Down

0 comments on commit b8a2f34

Please sign in to comment.