Skip to content

Commit

Permalink
Flow: types first in shared
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens committed Sep 30, 2022
1 parent 7b25b96 commit 7fc7d3e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
9 changes: 9 additions & 0 deletions packages/react/src/ReactServerContextRegistry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {ReactServerContext} from 'shared/ReactTypes';

export const ContextRegistry: {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/ReactErrorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function hasCaughtError(): boolean {
return hasError;
}

export function clearCaughtError() {
export function clearCaughtError(): mixed {
if (hasError) {
const error = caughtError;
hasError = false;
Expand Down
6 changes: 5 additions & 1 deletion packages/shared/ReactServerContextRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
* @flow
*/

import type {ReactServerContext} from 'shared/ReactTypes';

import {REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED} from 'shared/ReactSymbols';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {createServerContext} from 'react';

const ContextRegistry = ReactSharedInternals.ContextRegistry;

export function getOrCreateServerContext(globalName: string) {
export function getOrCreateServerContext(
globalName: string,
): ReactServerContext<any> {
if (!ContextRegistry[globalName]) {
ContextRegistry[globalName] = createServerContext(
globalName,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/enqueueTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let didWarnAboutMessageChannel = false;
let enqueueTaskImpl = null;

export default function enqueueTask(task: () => void) {
export default function enqueueTask(task: () => void): void {
if (enqueueTaskImpl === null) {
try {
// read require off the module object to get around the bundlers.
Expand Down
39 changes: 12 additions & 27 deletions packages/shared/invokeGuardedCallbackImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@
* @flow
*/

function invokeGuardedCallbackProd<A, B, C, D, E, F, Context>(
function invokeGuardedCallbackProd<Args: Array<mixed>, Context>(
name: string | null,
func: (a: A, b: B, c: C, d: D, e: E, f: F) => mixed,
func: (...Args) => mixed,
context: Context,
a: A,
b: B,
c: C,
d: D,
e: E,
f: F,
) {
): void {
const funcArgs = Array.prototype.slice.call(arguments, 3);
try {
// $FlowFixMe[incompatible-call] Flow doesn't understand the arguments splicing.
func.apply(context, funcArgs);
} catch (error) {
this.onError(error);
}
}

let invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
let invokeGuardedCallbackImpl: <Args: Array<mixed>, Context>(
name: string | null,
func: (...Args) => mixed,
context: Context,
) => void = invokeGuardedCallbackProd;

if (__DEV__) {
// In DEV mode, we swap out invokeGuardedCallback for a special version
Expand Down Expand Up @@ -59,24 +58,9 @@ if (__DEV__) {
const fakeNode = document.createElement('react');

invokeGuardedCallbackImpl = function invokeGuardedCallbackDev<
A,
B,
C,
D,
E,
F,
Args: Array<mixed>,
Context,
>(
name: string | null,
func: (a: A, b: B, c: C, d: D, e: E, f: F) => mixed,
context: Context,
a: A,
b: B,
c: C,
d: D,
e: E,
f: F,
) {
>(name: string | null, func: (...Args) => mixed, context: Context): void {
// If document doesn't exist we know for sure we will crash in this method
// when we call document.createEvent(). However this can cause confusing
// errors: https://github.com/facebook/create-react-app/issues/3482
Expand Down Expand Up @@ -142,6 +126,7 @@ if (__DEV__) {
function callCallback() {
didCall = true;
restoreAfterDispatch();
// $FlowFixMe[incompatible-call] Flow doesn't understand the arguments splicing.
func.apply(context, funcArgs);
didError = false;
}
Expand Down
1 change: 1 addition & 0 deletions scripts/flow/config/flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ well_formed_exports.includes=<PROJECT_ROOT>/packages/react-devtools-shared
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-devtools-shell
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-devtools-timeline
well_formed_exports.includes=<PROJECT_ROOT>/packages/scheduler
well_formed_exports.includes=<PROJECT_ROOT>/packages/shared

# Substituted by createFlowConfig.js:
%REACT_RENDERER_FLOW_OPTIONS%
Expand Down

0 comments on commit 7fc7d3e

Please sign in to comment.