Skip to content
Merged
Changes from 1 commit
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
Next Next commit
refactor: use ESM exports in ReactNativeViewConfigRegistry
  • Loading branch information
jbroma committed Oct 11, 2023
commit d4d003457b13d6aa4cd6a9d3f09d6971c47f8288
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {type ViewConfig} from './ReactNativeTypes';
import invariant from 'invariant';

// Event configs
const customBubblingEventTypes: {
export const customBubblingEventTypes: {
[eventName: string]: $ReadOnly<{
phasedRegistrationNames: $ReadOnly<{
captured: string,
Expand All @@ -24,16 +24,13 @@ const customBubblingEventTypes: {
}>,
...
} = {};
const customDirectEventTypes: {
export const customDirectEventTypes: {
[eventName: string]: $ReadOnly<{
registrationName: string,
}>,
...
} = {};

exports.customBubblingEventTypes = customBubblingEventTypes;
exports.customDirectEventTypes = customDirectEventTypes;

const viewConfigCallbacks = new Map<string, ?() => ViewConfig>();
const viewConfigs = new Map<string, ViewConfig>();

Expand Down Expand Up @@ -75,7 +72,7 @@ function processEventTypes(viewConfig: ViewConfig): void {
* A callback is provided to load the view config from UIManager.
* The callback is deferred until the view is actually rendered.
*/
exports.register = function (name: string, callback: () => ViewConfig): string {
export function register(name: string, callback: () => ViewConfig): string {
invariant(
!viewConfigCallbacks.has(name),
'Tried to register two views with the same name %s',
Expand All @@ -89,14 +86,14 @@ exports.register = function (name: string, callback: () => ViewConfig): string {
);
viewConfigCallbacks.set(name, callback);
return name;
};
}

/**
* Retrieves a config for the specified view.
* If this is the first time the view has been used,
* This configuration will be lazy-loaded from UIManager.
*/
exports.get = function (name: string): ViewConfig {
export function get(name: string): ViewConfig {
let viewConfig;
if (!viewConfigs.has(name)) {
const callback = viewConfigCallbacks.get(name);
Expand Down Expand Up @@ -124,4 +121,4 @@ exports.get = function (name: string): ViewConfig {
}
invariant(viewConfig, 'View config not found for name %s', name);
return viewConfig;
};
}