Skip to content

Commit bdc23fa

Browse files
iwoplazafacebook-github-bot
authored andcommitted
Migrate files in Libraries/Interaction to use export syntax (#48933)
Summary: Pull Request resolved: #48933 ## Motivation Modernising the react-native codebase to allow for ingestion by modern Flow tooling ## This diff - Updates files in Libraries/Interaction to use `export` syntax - Appends `.default` to requires of the changed files. - Updates the public API snapshot (intented breaking change) Changelog: [General][Breaking] - Files inside `Libraries/Interaction` use `export` syntax, which requires the addition of `.default` when imported with the CJS `require` syntax. Reviewed By: huntie Differential Revision: D68629953 fbshipit-source-id: 526b18d9b64c4b27b6e3198a9725075fa11e345a
1 parent 0f03449 commit bdc23fa

13 files changed

+31
-26
lines changed

packages/react-native/Libraries/Animated/__tests__/Animated-test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ describe('Animated', () => {
793793
beforeEach(() => {
794794
jest.mock('../../Interaction/InteractionManager');
795795
Animated = require('../Animated').default;
796-
InteractionManager = require('../../Interaction/InteractionManager');
796+
InteractionManager =
797+
require('../../Interaction/InteractionManager').default;
797798
});
798799

799800
afterEach(() => {

packages/react-native/Libraries/Interaction/FrameRateLogger.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ const FrameRateLogger = {
6969
},
7070
};
7171

72-
module.exports = FrameRateLogger;
72+
export default FrameRateLogger;

packages/react-native/Libraries/Interaction/InteractionManager.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import EventEmitter from '../vendor/emitter/EventEmitter';
1515

1616
const BatchedBridge = require('../BatchedBridge/BatchedBridge').default;
1717
const infoLog = require('../Utilities/infoLog').default;
18-
const TaskQueue = require('./TaskQueue');
18+
const TaskQueue = require('./TaskQueue').default;
1919
const invariant = require('invariant');
2020

2121
export type Handle = number;
@@ -77,7 +77,7 @@ const DEBUG: false = false;
7777
* allowing events such as touches to start interactions and block queued tasks
7878
* from executing, making apps more responsive.
7979
*/
80-
const InteractionManager = {
80+
const InteractionManagerImpl = {
8181
Events: {
8282
interactionStart: 'interactionStart',
8383
interactionComplete: 'interactionComplete',
@@ -210,8 +210,10 @@ function _processUpdate() {
210210
_deleteInteractionSet.clear();
211211
}
212212

213-
module.exports = (
213+
const InteractionManager = (
214214
ReactNativeFeatureFlags.disableInteractionManager()
215-
? require('./InteractionManagerStub')
216-
: InteractionManager
217-
) as typeof InteractionManager;
215+
? require('./InteractionManagerStub').default
216+
: InteractionManagerImpl
217+
) as typeof InteractionManagerImpl;
218+
219+
export default InteractionManager;

packages/react-native/Libraries/Interaction/InteractionManagerStub.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,4 @@ const InteractionManagerStub = {
173173
},
174174
};
175175

176-
module.exports = InteractionManagerStub;
176+
export default InteractionManagerStub;

packages/react-native/Libraries/Interaction/JSEventLoopWatchdog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ let longestStall = 0;
8585
let lastInterval = 0;
8686
const handlers: Array<Handler> = [];
8787

88-
module.exports = JSEventLoopWatchdog;
88+
export default JSEventLoopWatchdog;

packages/react-native/Libraries/Interaction/PanResponder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import type {PressEvent} from '../Types/CoreEventTypes';
1414

15-
const InteractionManager = require('./InteractionManager');
16-
const TouchHistoryMath = require('./TouchHistoryMath');
15+
const InteractionManager = require('./InteractionManager').default;
16+
const TouchHistoryMath = require('./TouchHistoryMath').default;
1717

1818
const currentCentroidXOfTouchesChangedAfter =
1919
TouchHistoryMath.currentCentroidXOfTouchesChangedAfter;

packages/react-native/Libraries/Interaction/TaskQueue.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@ class TaskQueue {
180180
}
181181
}
182182

183-
module.exports = TaskQueue;
183+
export default TaskQueue;

packages/react-native/Libraries/Interaction/TouchHistoryMath.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,4 @@ const TouchHistoryMath = {
179179
noCentroid: number,
180180
};
181181

182-
module.exports = TouchHistoryMath;
182+
export default TouchHistoryMath;

packages/react-native/Libraries/Interaction/__tests__/InteractionManager-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('InteractionManager', () => {
2929

3030
beforeEach(() => {
3131
jest.resetModules();
32-
InteractionManager = require('../InteractionManager');
32+
InteractionManager = require('../InteractionManager').default;
3333

3434
interactionStart = jest.fn();
3535
interactionComplete = jest.fn();
@@ -166,7 +166,7 @@ describe('promise tasks', () => {
166166
}
167167
beforeEach(() => {
168168
jest.resetModules();
169-
InteractionManager = require('../InteractionManager');
169+
InteractionManager = require('../InteractionManager').default;
170170
sequenceId = 0;
171171
});
172172

packages/react-native/Libraries/Interaction/__tests__/TaskQueue-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('TaskQueue', () => {
3636
beforeEach(() => {
3737
jest.resetModules();
3838
onMoreTasks = jest.fn();
39-
const TaskQueue = require('../TaskQueue');
39+
const TaskQueue = require('../TaskQueue').default;
4040
taskQueue = new TaskQueue({onMoreTasks});
4141
sequenceId = 0;
4242
});

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

+8-7
Original file line numberDiff line numberDiff line change
@@ -5328,13 +5328,13 @@ exports[`public API should not change unintentionally Libraries/Interaction/Fram
53285328
beginScroll(): void,
53295329
endScroll(): void,
53305330
};
5331-
declare module.exports: FrameRateLogger;
5331+
declare export default typeof FrameRateLogger;
53325332
"
53335333
`;
53345334

53355335
exports[`public API should not change unintentionally Libraries/Interaction/InteractionManager.js 1`] = `
53365336
"export type Handle = number;
5337-
declare const InteractionManager: {
5337+
declare const InteractionManagerImpl: {
53385338
Events: {
53395339
interactionStart: \\"interactionStart\\",
53405340
interactionComplete: \\"interactionComplete\\",
@@ -5352,7 +5352,8 @@ declare const InteractionManager: {
53525352
addListener: Function,
53535353
setDeadline(deadline: number): void,
53545354
};
5355-
declare module.exports: typeof InteractionManager;
5355+
declare const InteractionManager: typeof InteractionManagerImpl;
5356+
declare export default typeof InteractionManager;
53565357
"
53575358
`;
53585359

@@ -5386,7 +5387,7 @@ declare const InteractionManagerStub: {
53865387
addListener(): EventSubscription,
53875388
setDeadline(deadline: number): void,
53885389
};
5389-
declare module.exports: InteractionManagerStub;
5390+
declare export default typeof InteractionManagerStub;
53905391
"
53915392
`;
53925393

@@ -5402,7 +5403,7 @@ declare const JSEventLoopWatchdog: {
54025403
addHandler: (handler: Handler) => void,
54035404
install: ({ thresholdMS: number, ... }) => void,
54045405
};
5405-
declare module.exports: JSEventLoopWatchdog;
5406+
declare export default typeof JSEventLoopWatchdog;
54065407
"
54075408
`;
54085409

@@ -5502,7 +5503,7 @@ declare class TaskQueue {
55025503
_getCurrentQueue(): Array<Task>;
55035504
_genPromise(task: PromiseTask): void;
55045505
}
5505-
declare module.exports: TaskQueue;
5506+
declare export default typeof TaskQueue;
55065507
"
55075508
`;
55085509

@@ -5534,7 +5535,7 @@ exports[`public API should not change unintentionally Libraries/Interaction/Touc
55345535
currentCentroidY: (touchHistory: TouchHistoryMath) => number,
55355536
noCentroid: number,
55365537
};
5537-
declare module.exports: TouchHistoryMath;
5538+
declare export default typeof TouchHistoryMath;
55385539
"
55395540
`;
55405541

packages/react-native/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ module.exports = {
272272
return require('./Libraries/ReactNative/I18nManager');
273273
},
274274
get InteractionManager(): InteractionManager {
275-
return require('./Libraries/Interaction/InteractionManager');
275+
return require('./Libraries/Interaction/InteractionManager').default;
276276
},
277277
get Keyboard(): Keyboard {
278278
return require('./Libraries/Components/Keyboard/Keyboard').default;

packages/rn-tester/js/utils/useJsStalls.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const useJsStalls = (): ({
5656
}, []);
5757

5858
const onEnableJsStallsTracking = React.useCallback(() => {
59-
const JSEventLoopWatchdog = require('react-native/Libraries/Interaction/JSEventLoopWatchdog');
59+
const JSEventLoopWatchdog =
60+
require('react-native/Libraries/Interaction/JSEventLoopWatchdog').default;
6061

6162
JSEventLoopWatchdog.install({thresholdMS: 25});
6263

0 commit comments

Comments
 (0)