Skip to content
Open
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 @@ -30,7 +30,7 @@ type EventPropNames = {
};

// Cache of already-resolved event types.
const eventTypeToProps: {[string]: EventPropNames} = {};
const eventTypeToProps = new Map<string, EventPropNames>();

/**
* Converts a topLevelType (e.g., "topPointerUp") to a DOM event type
Expand Down Expand Up @@ -90,13 +90,13 @@ export function getEventTypePropName(
eventType: string,
isCapture: boolean,
): string | null {
const cached = eventTypeToProps[eventType];
const cached = eventTypeToProps.get(eventType);
if (cached !== undefined) {
return isCapture ? cached.captured : cached.bubbled;
}
const entry = findEventPropNames(eventType);
if (entry != null) {
eventTypeToProps[eventType] = entry;
eventTypeToProps.set(eventType, entry);
return isCapture ? entry.captured : entry.bubbled;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

import {customDirectEventTypes} from '../../../../../Libraries/Renderer/shims/ReactNativeViewConfigRegistry';
import {getEventTypePropName} from '../ReactNativeEventTypeMapping';

describe('ReactNativeEventTypeMapping', () => {
afterEach(() => {
delete customDirectEventTypes.topConstructor;
});

it('resolves event types that shadow Object prototype properties', () => {
customDirectEventTypes.topConstructor = {
registrationName: 'onConstructor',
};

expect(getEventTypePropName('constructor', false)).toBe('onConstructor');
expect(getEventTypePropName('constructor', true)).toBeNull();
});
});
Loading