Skip to content

Commit

Permalink
refactor: use ESM exports in ReactNativeViewConfigRegistry (#27508)
Browse files Browse the repository at this point in the history
## Summary

When transpiling `react-native` with `swc` this file caused some trouble
as it mixes ESM and CJS import/export syntax. This PR addresses this by
converting CJS exports to ESM exports. As
`ReactNativeViewConfigRegistry` is synced from `react` to `react-native`
repository, it's required to make the change here. I've also aligned the
mock of `ReactNativeViewConfigRegistry` to reflect current
implementation.

Related PR in `react-native`:
facebook/react-native#40787

DiffTrain build for commit ea8a861.
  • Loading branch information
javache committed Oct 12, 2023
1 parent a892e8a commit d1f9770
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24770,7 +24770,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-canary-e61a60fac-20231011";
var ReactVersion = "18.3.0-canary-ea8a8619c-20231012";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8968,7 +8968,7 @@ var devToolsConfig$jscomp$inline_1008 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-e61a60fac-20231011",
version: "18.3.0-canary-ea8a8619c-20231012",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1201 = {
Expand Down Expand Up @@ -8999,7 +8999,7 @@ var internals$jscomp$inline_1201 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-e61a60fac-20231011"
reconcilerVersion: "18.3.0-canary-ea8a8619c-20231012"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1202 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9394,7 +9394,7 @@ var devToolsConfig$jscomp$inline_1050 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-e61a60fac-20231011",
version: "18.3.0-canary-ea8a8619c-20231012",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1242 = {
Expand Down Expand Up @@ -9425,7 +9425,7 @@ var internals$jscomp$inline_1242 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-e61a60fac-20231011"
reconcilerVersion: "18.3.0-canary-ea8a8619c-20231012"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1243 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-canary-e61a60fac-20231011";
var ReactVersion = "18.3.0-canary-ea8a8619c-20231012";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-e61a60fac-20231011";
exports.version = "18.3.0-canary-ea8a8619c-20231012";
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-e61a60fac-20231011";
exports.version = "18.3.0-canary-ea8a8619c-20231012";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e61a60fac02d205ad928bff6de2449f00646a92c
ea8a8619ce51a0f8f0a78f87485e4e2a6f9d8c27
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noformat
* @flow strict-local
* @nolint
* @generated SignedSource<<1b39316520f5af25f0a141d7d78b0809>>
* @generated SignedSource<<3cf9b746913da1666cb5bce0ae12d978>>
*/

'use strict';
Expand All @@ -16,7 +16,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 @@ -26,16 +26,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 @@ -77,7 +74,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 @@ -91,14 +88,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 @@ -126,4 +123,4 @@ exports.get = function (name: string): ViewConfig {
}
invariant(viewConfig, 'View config not found for name %s', name);
return viewConfig;
};
}

0 comments on commit d1f9770

Please sign in to comment.