From 771d938fc01b2f18e15b4c755b67896bbf5a1da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Tue, 3 May 2016 14:37:13 -0700 Subject: [PATCH] Set up Flow - Yay! (#6682) This just configures flow to be checked and fixes our existing Flow typed files. Possible enhancements: Export .js.flow declarations from the build. Unclear whether this will be a supported workflow in the future or not, so let's wait on that. We should fail builds and CI on Flow errors. Ideally we should lint for Flow style guides (like no space before colon). --- .flowconfig | 34 ++++++++++++++ flow/environment.js | 20 +++++++++ flow/react-native-host-hooks.js | 44 +++++++++++++++++++ .../native/ReactNativeAttributePayload.js | 1 + .../native/ReactNativeBridgeEventPlugin.js | 8 ++-- .../native/ReactNativeContainerInfo.js | 2 +- src/renderers/native/ReactNativeMount.js | 2 +- 7 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 .flowconfig create mode 100644 flow/environment.js create mode 100644 flow/react-native-host-hooks.js diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000000000..72d5fe7925a01 --- /dev/null +++ b/.flowconfig @@ -0,0 +1,34 @@ +[ignore] + +.*/build/.* +.*/node_modules/y18n/.* +.*/__mocks__/.* +.*/__tests__/.* + +# Ignore Docs +.*/docs/.* + +[include] + +[libs] +./node_modules/fbjs/flow/lib +./flow + +[options] +module.system=haste + +esproposal.class_static_fields=enable +esproposal.class_instance_fields=enable + +munge_underscores=false + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FixMe + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*\\)?)\\)? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy + +[version] +0.24.0 diff --git a/flow/environment.js b/flow/environment.js new file mode 100644 index 0000000000000..fa020bf8aa50e --- /dev/null +++ b/flow/environment.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + */ + +/* eslint-disable */ + +declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{ + inject: ?((stuff: Object) => void) +};*/ + +// temporary patches for React.Component and React.Element +declare var ReactComponent: typeof React$Component; +declare var ReactElement: typeof React$Element; diff --git a/flow/react-native-host-hooks.js b/flow/react-native-host-hooks.js new file mode 100644 index 0000000000000..7c611324bbd9a --- /dev/null +++ b/flow/react-native-host-hooks.js @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + */ + +/* eslint-disable */ + +declare module 'deepDiffer' { + declare function exports(one: any, two: any): bool; +} +declare module 'deepFreezeAndThrowOnMutationInDev' { + declare function exports(obj : T) : T; +} +declare module 'flattenStyle' { } +declare module 'InitializeJavaScriptAppEngine' { } +declare module 'RCTEventEmitter' { + declare function register() : void; +} +declare module 'TextInputState' { + declare function blurTextInput(object : any) : void; + declare function focusTextInput(object : any) : void; +} +declare module 'UIManager' { + declare var customBubblingEventTypes : Object; + declare var customDirectEventTypes : Object; + declare function createView() : void; + declare function manageChildren() : void; + declare function measure() : void; + declare function measureInWindow() : void; + declare function measureLayout() : void; + declare function removeRootView() : void; + declare function removeSubviewsFromContainerWithID() : void; + declare function replaceExistingNonRootView() : void; + declare function setChildren() : void; + declare function setChildren() : void; + declare function updateView() : void; +} +declare module 'View' { } diff --git a/src/renderers/native/ReactNativeAttributePayload.js b/src/renderers/native/ReactNativeAttributePayload.js index a2976c6025066..4aaa8064494f8 100644 --- a/src/renderers/native/ReactNativeAttributePayload.js +++ b/src/renderers/native/ReactNativeAttributePayload.js @@ -394,6 +394,7 @@ function diffProperties( // default: fallthrough case when nested properties are defined removedKeys = null; removedKeyCount = 0; + // $FlowFixMe - We think that attributeConfig is not CustomAttributeConfiguration at this point so we assume it must be AttributeConfiguration. updatePayload = diffNestedProperty( updatePayload, prevProp, diff --git a/src/renderers/native/ReactNativeBridgeEventPlugin.js b/src/renderers/native/ReactNativeBridgeEventPlugin.js index 97c6496c6a258..1e5f4ee7af53f 100644 --- a/src/renderers/native/ReactNativeBridgeEventPlugin.js +++ b/src/renderers/native/ReactNativeBridgeEventPlugin.js @@ -43,10 +43,10 @@ var ReactNativeBridgeEventPlugin = { * @see {EventPluginHub.extractEvents} */ extractEvents: function( - topLevelType, - targetInst, - nativeEvent, - nativeEventTarget + topLevelType: string, + targetInst: Object, + nativeEvent: Event, + nativeEventTarget: Object ): ?Object { var bubbleDispatchConfig = customBubblingEventTypes[topLevelType]; var directDispatchConfig = customDirectEventTypes[topLevelType]; diff --git a/src/renderers/native/ReactNativeContainerInfo.js b/src/renderers/native/ReactNativeContainerInfo.js index cc37ede4a09d1..6d24f4c75156f 100644 --- a/src/renderers/native/ReactNativeContainerInfo.js +++ b/src/renderers/native/ReactNativeContainerInfo.js @@ -11,7 +11,7 @@ */ 'use strict'; -function ReactNativeContainerInfo(tag) { +function ReactNativeContainerInfo(tag: number) { var info = { _tag: tag, }; diff --git a/src/renderers/native/ReactNativeMount.js b/src/renderers/native/ReactNativeMount.js index 6800b49cb9a7d..caa67419806af 100644 --- a/src/renderers/native/ReactNativeMount.js +++ b/src/renderers/native/ReactNativeMount.js @@ -233,7 +233,7 @@ var ReactNativeMount = { */ unmountComponentFromNode: function( instance: ReactComponent, - containerID: string + containerID: number ) { // Call back into native to remove all of the subviews from this container ReactReconciler.unmountComponent(instance);