Skip to content

Commit

Permalink
[WIP] Flow
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed May 17, 2018
1 parent 22e6ea3 commit 267d1f4
Show file tree
Hide file tree
Showing 30 changed files with 503 additions and 382 deletions.
8 changes: 8 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<PROJECT_ROOT>/.*/__mocks__/.*
<PROJECT_ROOT>/.*/__tests__/.*

# TODO
<PROJECT_ROOT>/packages/react-noop-renderer/.*

[include]

[libs]
Expand All @@ -29,6 +32,11 @@ esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable
unsafe.enable_getters_and_setters=true

# This would enable ReactDOM-specific check.
# TODO: scripts that run this.
# module.name_mapper='react-reconciler/inline.dom$' -> 'react-reconciler/inline.typed'
# module.name_mapper='ReactFiberHostConfig' -> '<PROJECT_ROOT>/packages/react-dom/src/client/ReactDOMHostConfig'

munge_underscores=false

suppress_type=$FlowIssue
Expand Down
2 changes: 1 addition & 1 deletion packages/react-art/src/ReactART.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import * as ARTRenderer from 'react-reconciler/inline';
import * as ARTRenderer from 'react-reconciler/inline.art';
import Transform from 'art/core/transform';
import Mode from 'art/modes/current';
import FastNoSideEffects from 'art/modes/fast-noSideEffects';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {Container} from './ReactDOMHostConfig';
import '../shared/checkReact';
import './ReactDOMClientInjection';

import * as DOMRenderer from 'react-reconciler/inline';
import * as DOMRenderer from 'react-reconciler/inline.dom';
import * as ReactPortal from 'shared/ReactPortal';
import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
import * as ReactGenericBatching from 'events/ReactGenericBatching';
Expand Down
51 changes: 44 additions & 7 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ import {
DOCUMENT_FRAGMENT_NODE,
} from '../shared/HTMLNodeType';


export type T = string;
export type P = any;
export type I = Element;
export type TI = Text;
export type HI = any;
export type PI = Element | Text;
export type C = Element | Document;
export type CC = void;
export type CX = string | { namespace: string, ancestorInfo: mixed };
export type PL = Array<mixed>;


export type Container = Element | Document;
type Props = {
autoFocus?: boolean,
Expand Down Expand Up @@ -111,6 +124,7 @@ export function getRootHostContext(rootContainerInstance: Container): HostContex
export function getChildHostContext(
parentHostContext: HostContext,
type: string,
instance: *
): HostContext {
if (__DEV__) {
const parentHostContextDev = ((parentHostContext: any): HostContextDev);
Expand All @@ -130,13 +144,13 @@ export function getPublicInstance(instance: Instance | TextInstance): * {
return instance;
}

export function prepareForCommit(): void {
export function prepareForCommit(containerInfo: *): void {
eventsEnabled = ReactBrowserEventEmitter.isEnabled();
selectionInformation = ReactInputSelection.getSelectionInformation();
ReactBrowserEventEmitter.setEnabled(false);
}

export function resetAfterCommit(): void {
export function resetAfterCommit(containerInfo: *): void {
ReactInputSelection.restoreSelection(selectionInformation);
selectionInformation = null;
ReactBrowserEventEmitter.setEnabled(eventsEnabled);
Expand Down Expand Up @@ -194,6 +208,7 @@ export function finalizeInitialChildren(
type: string,
props: Props,
rootContainerInstance: Container,
hostContext: *,
): boolean {
setInitialProperties(domElement, type, props, rootContainerInstance);
return shouldAutoFocusHostComponent(type, props);
Expand Down Expand Up @@ -566,23 +581,45 @@ export function prepareUpdate(
export const cancelDeferredCallback = ReactScheduler.cancelScheduledWork;


export function cloneInstance() {
// TODO

export function cloneInstance(
instance: Instance,
updatePayload: null | Array<mixed>,
type: string,
oldProps: Props,
newProps: Props,
internalInstanceHandle: Object,
keepChildren: boolean,
recyclableInstance: Instance,
): Instance {
return instance;
// not supported
}

export function createContainerChildSet() {
export function createContainerChildSet(
container: Container
): void {
// not supported
}

export function appendChildToContainerChildSet() {
export function appendChildToContainerChildSet(
childSet: void, child: Instance | TextInstance
): void {
// not supported
}

export function finalizeContainerChildren() {
export function finalizeContainerChildren(
container: Container,
newChildren: void
) {
// not supported
}

export function replaceContainerChildren() {
export function replaceContainerChildren(
container: Container,
newChildren: void
) {
// not supported
}

2 changes: 1 addition & 1 deletion packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {ReactNodeList} from 'shared/ReactTypes';

import './ReactFabricInjection';

import * as ReactFabricRenderer from 'react-reconciler/inline';
import * as ReactFabricRenderer from 'react-reconciler/inline.fabric';

import * as ReactPortal from 'shared/ReactPortal';
import * as ReactGenericBatching from 'events/ReactGenericBatching';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {ReactNodeList} from 'shared/ReactTypes';

import './ReactNativeInjection';

import * as ReactNativeFiberRenderer from 'react-reconciler/inline';
import * as ReactNativeFiberRenderer from 'react-reconciler/inline.native';
import * as ReactPortal from 'shared/ReactPortal';
import * as ReactGenericBatching from 'events/ReactGenericBatching';
import ReactVersion from 'shared/ReactVersion';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @ TODO !!!!!!!!!!!!!!!!!!
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @ TODO !!!!!!!!!!!!!!!!!!
*/

'use strict';
Expand Down
2 changes: 2 additions & 0 deletions packages/react-reconciler/inline.art.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO
export * from './src/ReactFiberReconciler';
2 changes: 2 additions & 0 deletions packages/react-reconciler/inline.dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO
export * from './src/ReactFiberReconciler';
2 changes: 2 additions & 0 deletions packages/react-reconciler/inline.fabric.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO
export * from './src/ReactFiberReconciler';
2 changes: 2 additions & 0 deletions packages/react-reconciler/inline.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO
export * from './src/ReactFiberReconciler';
2 changes: 2 additions & 0 deletions packages/react-reconciler/inline.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO
export * from './src/ReactFiberReconciler';
4 changes: 4 additions & 0 deletions packages/react-reconciler/inline.typed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @flow

// TODO
export * from './src/ReactFiberReconciler';
6 changes: 0 additions & 6 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@
* @flow
*/

import type {HostConfig} from 'react-reconciler';
import type {ReactProviderType, ReactContext} from 'shared/ReactTypes';
import type {Fiber} from 'react-reconciler/src/ReactFiber';
import type {HostContext} from './ReactFiberHostContext';
import type {LegacyContext} from './ReactFiberContext';
import type {NewContext} from './ReactFiberNewContext';
import type {HydrationContext} from './ReactFiberHydrationContext';
import type {FiberRoot} from './ReactFiberRoot';
import type {ExpirationTime} from './ReactFiberExpirationTime';
import type {ProfilerTimer} from './ReactProfilerTimer';
import checkPropTypes from 'prop-types/checkPropTypes';

import {
Expand Down
1 change: 0 additions & 1 deletion packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import type {Fiber} from './ReactFiber';
import type {ExpirationTime} from './ReactFiberExpirationTime';
import type {LegacyContext} from './ReactFiberContext';

import {Update, Snapshot} from 'shared/ReactTypeOfSideEffect';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {HostConfig} from 'react-reconciler';
import type {I, TI, C, CC, PL} from './ReactFiberHostConfig';
import type {Fiber} from './ReactFiber';
import type {FiberRoot} from './ReactFiberRoot';
import type {ExpirationTime} from './ReactFiberExpirationTime';
Expand Down
7 changes: 1 addition & 6 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
* @flow
*/

import type {HostConfig} from 'react-reconciler';
import type {Fiber} from './ReactFiber';
import type {ExpirationTime} from './ReactFiberExpirationTime';
import type {HostContext} from './ReactFiberHostContext';
import type {LegacyContext} from './ReactFiberContext';
import type {NewContext} from './ReactFiberNewContext';
import type {HydrationContext} from './ReactFiberHydrationContext';
import type {FiberRoot} from './ReactFiberRoot';
import type {ProfilerTimer} from './ReactProfilerTimer';
import type {T, P, I, TI, HI, PI, C, CC, CX, PL} from './ReactFiberHostConfig';

import {
enableMutatingReconciler,
Expand Down
32 changes: 4 additions & 28 deletions packages/react-reconciler/src/ReactFiberContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type {Fiber} from './ReactFiber';
import type {StackCursor, Stack} from './ReactFiberStack';
import type {StackCursor} from './ReactFiberStack';

import {isFiberMounted} from 'react-reconciler/reflection';
import {ClassComponent, HostRoot} from 'shared/ReactTypeOfWork';
Expand All @@ -28,30 +28,6 @@ if (__DEV__) {
warnedAboutMissingGetChildContext = {};
}

export type LegacyContext = {
getUnmaskedContext(workInProgress: Fiber): Object,
cacheContext(
workInProgress: Fiber,
unmaskedContext: Object,
maskedContext: Object,
): void,
getMaskedContext(workInProgress: Fiber, unmaskedContext: Object): Object,
hasContextChanged(): boolean,
isContextConsumer(fiber: Fiber): boolean,
isContextProvider(fiber: Fiber): boolean,
popContextProvider(fiber: Fiber): void,
popTopLevelContextObject(fiber: Fiber): void,
pushTopLevelContextObject(
fiber: Fiber,
context: Object,
didChange: boolean,
): void,
processChildContext(fiber: Fiber, parentContext: Object): Object,
pushContextProvider(workInProgress: Fiber): boolean,
invalidateContextProvider(workInProgress: Fiber, didChange: boolean): void,
findCurrentUnmaskedContext(fiber: Fiber): Object,
};

// A cursor to the current merged context object on the stack.
let contextStackCursor: StackCursor<Object> = createCursor(emptyObject);
// A cursor to a boolean indicating whether the context has changed.
Expand All @@ -77,13 +53,13 @@ export type LegacyContext = {
workInProgress: Fiber,
unmaskedContext: Object,
maskedContext: Object,
) {
): void {
const instance = workInProgress.stateNode;
instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
}

function getMaskedContext(workInProgress: Fiber, unmaskedContext: Object) {
function getMaskedContext(workInProgress: Fiber, unmaskedContext: Object): Object {
const type = workInProgress.type;
const contextTypes = type.contextTypes;
if (!contextTypes) {
Expand Down Expand Up @@ -147,7 +123,7 @@ export type LegacyContext = {
pop(contextStackCursor, fiber);
}

function popTopLevelContextObject(fiber: Fiber) {
function popTopLevelContextObject(fiber: Fiber): void {
pop(didPerformWorkStackCursor, fiber);
pop(contextStackCursor, fiber);
}
Expand Down

0 comments on commit 267d1f4

Please sign in to comment.