Skip to content

Commit

Permalink
Codemod cycle annotations for xplat/js
Browse files Browse the repository at this point in the history
Summary:
Add annotations using flow codemod annotate-cycles --write

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D40896688

fbshipit-source-id: 0c32932d17542be070360db29b7797f8e6e5978b
  • Loading branch information
mvitousek authored and facebook-github-bot committed Nov 2, 2022
1 parent d71d0db commit 91d58cf
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 22 deletions.
6 changes: 3 additions & 3 deletions IntegrationTests/TimersTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TimersTest extends React.Component<Props, State> {
};

setTimeout(fn: () => void, time: number): TimeoutID {
const id = setTimeout(() => {
const id: TimeoutID = setTimeout(() => {
this._timeoutIDs.delete(id);
fn();
}, time);
Expand Down Expand Up @@ -70,7 +70,7 @@ class TimersTest extends React.Component<Props, State> {
}

setImmediate(fn: () => void): ImmediateID {
const id = setImmediate(() => {
const id: any = setImmediate(() => {
this._immediateIDs.delete(id);
fn();
});
Expand All @@ -81,7 +81,7 @@ class TimersTest extends React.Component<Props, State> {
}

requestAnimationFrame(fn: () => void): AnimationFrameID {
const id = requestAnimationFrame(() => {
const id: AnimationFrameID = requestAnimationFrame(() => {
this._animationFrameIDs.delete(id);
fn();
});
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Animated/AnimatedImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ const parallel = function (
});
},

_startNativeLoop: function () {
_startNativeLoop: function (): empty {
throw new Error(
'Loops run using the native driver cannot contain Animated.parallel animations',
);
Expand Down
2 changes: 1 addition & 1 deletion Libraries/BatchedBridge/MessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class MessageQueue {
// folly-convertible. As a special case, if a prop value is a
// function it is permitted here, and special-cased in the
// conversion.
const isValidArgument = (val: mixed) => {
const isValidArgument = (val: mixed): boolean => {
switch (typeof val) {
case 'undefined':
case 'boolean':
Expand Down
2 changes: 1 addition & 1 deletion Libraries/BugReporting/getReactData.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function copyWithSetImpl(
path: Array<string | number>,
idx: number,
value: any,
) {
): any {
if (idx >= path.length) {
return value;
}
Expand Down
19 changes: 11 additions & 8 deletions Libraries/Core/Timers/JSTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const JSTimers = {
* @param {function} func Callback to be invoked before the end of the
* current JavaScript execution loop.
*/
queueReactNativeMicrotask: function (func: Function, ...args: any) {
queueReactNativeMicrotask: function (func: Function, ...args: any): number {
const id = _allocateCallback(
() => func.apply(undefined, args),
'queueReactNativeMicrotask',
Expand All @@ -254,7 +254,7 @@ const JSTimers = {
/**
* @param {function} func Callback to be invoked every frame.
*/
requestAnimationFrame: function (func: Function) {
requestAnimationFrame: function (func: Function): any | number {
const id = _allocateCallback(func, 'requestAnimationFrame');
createTimer(id, 1, Date.now(), /* recurring */ false);
return id;
Expand All @@ -265,16 +265,19 @@ const JSTimers = {
* with time remaining in frame.
* @param {?object} options
*/
requestIdleCallback: function (func: Function, options: ?Object) {
requestIdleCallback: function (
func: Function,
options: ?Object,
): any | number {
if (requestIdleCallbacks.length === 0) {
setSendIdleEvents(true);
}

const timeout = options && options.timeout;
const id = _allocateCallback(
const id: number = _allocateCallback(
timeout != null
? (deadline: any) => {
const timeoutId = requestIdleCallbackTimeouts[id];
const timeoutId: number = requestIdleCallbackTimeouts[id];
if (timeoutId) {
JSTimers.clearTimeout(timeoutId);
delete requestIdleCallbackTimeouts[id];
Expand All @@ -287,8 +290,8 @@ const JSTimers = {
requestIdleCallbacks.push(id);

if (timeout != null) {
const timeoutId = JSTimers.setTimeout(() => {
const index = requestIdleCallbacks.indexOf(id);
const timeoutId: number = JSTimers.setTimeout(() => {
const index: number = requestIdleCallbacks.indexOf(id);
if (index > -1) {
requestIdleCallbacks.splice(index, 1);
_callTimer(id, global.performance.now(), true);
Expand Down Expand Up @@ -345,7 +348,7 @@ const JSTimers = {
* This is called from the native side. We are passed an array of timerIDs,
* and
*/
callTimers: function (timersToCall: Array<number>) {
callTimers: function (timersToCall: Array<number>): any | void {
invariant(
timersToCall.length !== 0,
'Cannot call `callTimers` with an empty list of IDs.',
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Lists/ViewabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class ViewabilityHelper {
}
this._viewableIndices = viewableIndices;
if (this._config.minimumViewTime) {
const handle = setTimeout(() => {
const handle: TimeoutID = setTimeout(() => {
/* $FlowFixMe[incompatible-call] (>=0.63.0 site=react_native_fb) This
* comment suppresses an error found when Flow v0.63 was deployed. To
* see the error delete this comment and run Flow. */
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LogBox/Data/LogBoxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const observers: Set<{observer: Observer, ...}> = new Set();
const ignorePatterns: Set<IgnorePattern> = new Set();
let appInfo: ?() => AppInfo = null;
let logs: LogBoxLogs = new Set();
let updateTimeout = null;
let updateTimeout: $FlowFixMe | null = null;
let _isDisabled = false;
let _selectedIndex = -1;

Expand Down
9 changes: 7 additions & 2 deletions Libraries/vendor/emitter/__tests__/EventEmitter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* @oncall react_native
*/

import type {EventSubscription} from '../EventEmitter';

import EventEmitter from '../EventEmitter';

describe('listeners', () => {
Expand Down Expand Up @@ -309,15 +311,18 @@ describe('event emission', () => {
const listenerA = jest.fn(() => {
results.push('A');
});
const listenerB = jest.fn(() => {
const listenerB: JestMockFn<Array<mixed>, void> = jest.fn(() => {
results.push('B');
subscriptionB.remove();
});
const listenerC = jest.fn(() => {
results.push('C');
});
emitter.addListener('A', listenerA);
const subscriptionB = emitter.addListener('A', listenerB);
const subscriptionB: EventSubscription = emitter.addListener(
'A',
listenerB,
);
emitter.addListener('A', listenerC);

emitter.emit('A');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function getParamObjCType(
function getReturnObjCType(
methodName: string,
nullableTypeAnnotation: Nullable<NativeModuleReturnTypeAnnotation>,
) {
): string {
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);

function wrapIntoNullableIfNeeded(generatedType: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ function findEventArgumentsAndType(
types: TypeMap,
bubblingType: void | 'direct' | 'bubble',
paperName: ?$FlowFixMe,
) {
): {
argumentProps: $FlowFixMe,
bubblingType: ?('direct' | 'bubble'),
paperTopLevelNameDeprecated: ?$FlowFixMe,
} {
if (!typeAnnotation.id) {
throw new Error("typeAnnotation of event doesn't have a name");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function ToggleAnimatingActivityIndicator() {

const [animating, setAnimating] = useState(true);

const setToggleTimeout = useCallback(() => {
const setToggleTimeout: () => void = useCallback(() => {
timer.current = setTimeout(() => {
setAnimating(currentState => !currentState);
setToggleTimeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AnExTilt extends React.Component<Object, any> {
useNativeDriver: false,
}).start();
this.state.panX.removeAllListeners();
const id = this.state.panX.addListener(({value}) => {
const id: any = this.state.panX.addListener(({value}) => {
// listen until offscreen
if (Math.abs(value) > 400) {
this.state.panX.removeListener(id); // offscreen, so stop listening
Expand Down

0 comments on commit 91d58cf

Please sign in to comment.