Skip to content

Commit 0f45d33

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
move Fantom's API to regular functions (facebook#50035)
Summary: Pull Request resolved: facebook#50035 changelog: [internal] to make it easier to write JSDocs, let's export functions directly from index.js instead of using proxy object. Reviewed By: rubennorte Differential Revision: D71200977 fbshipit-source-id: 0b53c0d3f73577c19253537b9e884459a4920643
1 parent 827db0a commit 0f45d33

File tree

26 files changed

+41
-53
lines changed

26 files changed

+41
-53
lines changed

packages/react-native-fantom/runner/getFantomTestConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const DEFAULT_MODE: FantomTestConfigMode =
5454
const FANTOM_FLAG_FORMAT = /^(\w+):(\w+)$/;
5555

5656
const FANTOM_BENCHMARK_FILENAME_RE = /[Bb]enchmark-itest\./g;
57-
const FANTOM_BENCHMARK_SUITE_RE = /\nFantom\.unstable_benchmark(\s*)\.suite\(/g;
57+
const FANTOM_BENCHMARK_SUITE_RE =
58+
/\n(Fantom\.)?unstable_benchmark(\s*)\.suite\(/g;
5859

5960
/**
6061
* Extracts the Fantom configuration from the test file, specified as part of

packages/react-native-fantom/src/__tests__/Fantom-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'react-native/Libraries/Core/InitializeCore';
1313

1414
import type {Root} from '@react-native/fantom';
1515

16-
import Fantom from '@react-native/fantom';
16+
import * as Fantom from '@react-native/fantom';
1717
import * as React from 'react';
1818
import {Modal, ScrollView, Text, TextInput, View} from 'react-native';
1919
import NativeFantom from 'react-native/src/private/testing/fantom/specs/NativeFantom';

packages/react-native-fantom/src/__tests__/benchmarks/BenchmarkTests-testMode-benchmark-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @oncall react_native
1010
*/
1111

12-
import Fantom from '@react-native/fantom';
12+
import * as Fantom from '@react-native/fantom';
1313

1414
let runs = 0;
1515

packages/react-native-fantom/src/index.js

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const DEFAULT_TASK_PRIORITY = schedulerPriorityImmediate;
130130
* If the work loop is running, it will be executed according to its priority.
131131
* Otherwise, it will wait in the queue until the work loop runs.
132132
*/
133-
function scheduleTask(task: () => void | Promise<void>) {
133+
export function scheduleTask(task: () => void | Promise<void>) {
134134
nativeRuntimeScheduler.unstable_scheduleCallback(DEFAULT_TASK_PRIORITY, task);
135135
}
136136

@@ -141,7 +141,7 @@ let flushingQueue = false;
141141
*
142142
* React must run inside of event loop to ensure scheduling environment is closer to production.
143143
*/
144-
function runTask(task: () => void | Promise<void>) {
144+
export function runTask(task: () => void | Promise<void>) {
145145
if (flushingQueue) {
146146
throw new Error(
147147
'Nested `runTask` calls are not allowed. If you want to schedule a task from inside another task, use `scheduleTask` instead.',
@@ -155,7 +155,7 @@ function runTask(task: () => void | Promise<void>) {
155155
/*
156156
* Simmulates running a task on the UI thread and forces side effect to drain the event queue, scheduling events to be dispatched to JavaScript.
157157
*/
158-
function runOnUIThread(task: () => void) {
158+
export function runOnUIThread(task: () => void) {
159159
task();
160160
NativeFantom.flushEventQueue();
161161
}
@@ -164,15 +164,15 @@ function runOnUIThread(task: () => void) {
164164
* Runs a side effect to drain the event queue and dispatches events to JavaScript.
165165
* Useful to flash out all tasks.
166166
*/
167-
function flushAllNativeEvents() {
167+
export function flushAllNativeEvents() {
168168
NativeFantom.flushEventQueue();
169169
runWorkLoop();
170170
}
171171

172172
/**
173173
* Runs the event loop until all tasks are executed.
174174
*/
175-
function runWorkLoop(): void {
175+
export function runWorkLoop(): void {
176176
if (flushingQueue) {
177177
throw new Error(
178178
'Cannot start the work loop because it is already running. If you want to schedule a task from inside another task, use `scheduleTask` instead.',
@@ -189,7 +189,7 @@ function runWorkLoop(): void {
189189

190190
// TODO: Add option to define surface props and pass it to startSurface
191191
// Surfacep rops: concurrentRoot, surfaceWidth, surfaceHeight, layoutDirection, pointScaleFactor.
192-
function createRoot(rootConfig?: RootConfig): Root {
192+
export function createRoot(rootConfig?: RootConfig): Root {
193193
return new Root(rootConfig);
194194
}
195195

@@ -200,7 +200,7 @@ function createRoot(rootConfig?: RootConfig): Root {
200200
*
201201
* For a higher level API, use `dispatchNativeEvent`.
202202
*/
203-
function enqueueNativeEvent(
203+
export function enqueueNativeEvent(
204204
node: ReactNativeElement,
205205
type: string,
206206
payload?: {[key: string]: mixed},
@@ -216,7 +216,7 @@ function enqueueNativeEvent(
216216
);
217217
}
218218

219-
function dispatchNativeEvent(
219+
export function dispatchNativeEvent(
220220
node: ReactNativeElement,
221221
type: string,
222222
payload?: {[key: string]: mixed},
@@ -235,7 +235,7 @@ export type ScrollEventOptions = {
235235
zoomScale?: number,
236236
};
237237

238-
function enqueueScrollEvent(
238+
export function enqueueScrollEvent(
239239
node: ReactNativeElement,
240240
options: ScrollEventOptions,
241241
) {
@@ -271,15 +271,18 @@ function enqueueScrollEvent(
271271
* // Assert that changes from Fantom.scrollTo are in effect.
272272
* ```
273273
*/
274-
function scrollTo(node: ReactNativeElement, options: ScrollEventOptions) {
274+
export function scrollTo(
275+
node: ReactNativeElement,
276+
options: ScrollEventOptions,
277+
) {
275278
runOnUIThread(() => {
276279
enqueueScrollEvent(node, options);
277280
});
278281

279282
runWorkLoop();
280283
}
281284

282-
function enqueueModalSizeUpdate(
285+
export function enqueueModalSizeUpdate(
283286
node: ReactNativeElement,
284287
size: {width: number, height: number},
285288
) {
@@ -369,26 +372,10 @@ if (typeof global.EventTarget === 'undefined') {
369372
);
370373
}
371374

372-
function saveJSMemoryHeapSnapshot(filePath: string): void {
375+
export function saveJSMemoryHeapSnapshot(filePath: string): void {
373376
if (getConstants().isRunningFromCI) {
374377
throw new Error('Unexpected call to `saveJSMemoryHeapSnapshot` from CI');
375378
}
376379

377380
NativeFantom.saveJSMemoryHeapSnapshot(filePath);
378381
}
379-
380-
export default {
381-
scheduleTask,
382-
runTask,
383-
runOnUIThread,
384-
runWorkLoop,
385-
createRoot,
386-
dispatchNativeEvent,
387-
enqueueNativeEvent,
388-
flushAllNativeEvents,
389-
enqueueModalSizeUpdate,
390-
unstable_benchmark: Benchmark,
391-
enqueueScrollEvent,
392-
scrollTo,
393-
saveJSMemoryHeapSnapshot,
394-
};

packages/react-native/Libraries/Components/ScrollView/__tests__/ScrollView-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import 'react-native/Libraries/Core/InitializeCore';
1313

14-
import Fantom from '@react-native/fantom';
14+
import * as Fantom from '@react-native/fantom';
1515
import * as React from 'react';
1616
import {ScrollView} from 'react-native';
1717
import ensureInstance from 'react-native/src/private/utilities/ensureInstance';

packages/react-native/Libraries/Components/ScrollView/__tests__/ScrollView-viewCulling-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
import 'react-native/Libraries/Core/InitializeCore.js';
15-
import Fantom from '@react-native/fantom';
15+
import * as Fantom from '@react-native/fantom';
1616
import * as React from 'react';
1717
import {Modal, ScrollView, View} from 'react-native';
1818
import ensureInstance from 'react-native/src/private/utilities/ensureInstance';

packages/react-native/Libraries/Components/TextInput/__tests__/TextInput-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import 'react-native/Libraries/Core/InitializeCore';
1313

14-
import Fantom from '@react-native/fantom';
14+
import * as Fantom from '@react-native/fantom';
1515
import * as React from 'react';
1616
import {useEffect, useLayoutEffect, useRef} from 'react';
1717
import {TextInput} from 'react-native';

packages/react-native/Libraries/Components/View/__tests__/View-benchmark-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import 'react-native/Libraries/Core/InitializeCore';
1313

14-
import Fantom from '@react-native/fantom';
14+
import * as Fantom from '@react-native/fantom';
1515
import * as React from 'react';
1616
import {View} from 'react-native';
1717

packages/react-native/Libraries/Components/View/__tests__/View-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import 'react-native/Libraries/Core/InitializeCore';
1313

14-
import Fantom from '@react-native/fantom';
14+
import * as Fantom from '@react-native/fantom';
1515
import * as React from 'react';
1616
import {View} from 'react-native';
1717

packages/react-native/Libraries/LogBox/__tests__/LogBox-itest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import 'react-native/Libraries/Core/InitializeCore';
1313

1414
import {renderLogBox} from './fantomHelpers';
15-
import Fantom from '@react-native/fantom';
15+
import * as Fantom from '@react-native/fantom';
1616
import * as React from 'react';
1717
import {useEffect} from 'react';
1818
import {LogBox, Text, View} from 'react-native';

0 commit comments

Comments
 (0)