[Flow] Clean up react-native for Flow v0.15.0

This commit is contained in:
Gabe Levi 2015-09-04 17:00:21 -07:00
parent 936e1d4a11
commit 874f39bf7f
5 changed files with 70 additions and 54 deletions

View File

@ -22,7 +22,9 @@ var {
var MAX_VALUE = 200; var MAX_VALUE = 200;
function getStyleFromScore(score: number): {color: string} { import type { StyleObj } from 'StyleSheetTypes';
function getStyleFromScore(score: number): StyleObj {
if (score < 0) { if (score < 0) {
return styles.noScore; return styles.noScore;
} }

View File

@ -72,7 +72,9 @@ function setupDevtools() {
} }
function handleMessage(evt) { function handleMessage(evt) {
var data; // It's hard to handle JSON in a safe manner without inspecting it at
// runtime, hence the any
var data: any;
try { try {
data = JSON.parse(evt.data); data = JSON.parse(evt.data);
} catch (e) { } catch (e) {

View File

@ -138,6 +138,23 @@ type ConnectivityStateAndroid = $Enum<{
var _subscriptions = new Map(); var _subscriptions = new Map();
if (Platform.OS === 'ios') {
var _isConnected = function(
reachability: ReachabilityStateIOS
): bool {
return reachability !== 'none' &&
reachability !== 'unknown';
};
} else if (Platform.OS === 'android') {
var _isConnected = function(
connectionType: ConnectivityStateAndroid
): bool {
return connectionType !== 'NONE' && connectionType !== 'UNKNOWN';
};
}
var _isConnectedSubscriptions = new Map();
var NetInfo = { var NetInfo = {
addEventListener: function ( addEventListener: function (
eventName: ChangeEventName, eventName: ChangeEventName,
@ -175,60 +192,41 @@ var NetInfo = {
}); });
}, },
isConnected: {}, isConnected: {
addEventListener: function (
eventName: ChangeEventName,
handler: Function
): void {
var listener = (connection) => {
handler(_isConnected(connection));
};
_isConnectedSubscriptions.set(handler, listener);
NetInfo.addEventListener(
eventName,
listener
);
},
isConnectionMetered: {}, removeEventListener: function(
}; eventName: ChangeEventName,
handler: Function
): void {
var listener = _isConnectedSubscriptions.get(handler);
NetInfo.removeEventListener(
eventName,
listener
);
_isConnectedSubscriptions.delete(handler);
},
if (Platform.OS === 'ios') { fetch: function(): Promise {
var _isConnected = function( return NetInfo.fetch().then(
reachability: ReachabilityStateIOS (connection) => _isConnected(connection)
): bool { );
return reachability !== 'none' && },
reachability !== 'unknown';
};
} else if (Platform.OS === 'android') {
var _isConnected = function(
connectionType: ConnectivityStateAndroid
): bool {
return connectionType !== 'NONE' && connectionType !== 'UNKNOWN';
};
}
var _isConnectedSubscriptions = new Map();
NetInfo.isConnected = {
addEventListener: function (
eventName: ChangeEventName,
handler: Function
): void {
var listener = (connection) => {
handler(_isConnected(connection));
};
_isConnectedSubscriptions.set(handler, listener);
NetInfo.addEventListener(
eventName,
listener
);
}, },
removeEventListener: function( isConnectionMetered: ({}: {} | (callback:Function) => void),
eventName: ChangeEventName,
handler: Function
): void {
var listener = _isConnectedSubscriptions.get(handler);
NetInfo.removeEventListener(
eventName,
listener
);
_isConnectedSubscriptions.delete(handler);
},
fetch: function(): Promise {
return NetInfo.fetch().then(
(connection) => _isConnected(connection)
);
},
}; };
if (Platform.OS === 'android') { if (Platform.OS === 'android') {

View File

@ -0,0 +1,15 @@
/**
* 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.
*
* @providesModule StyleSheetTypes
* @flow
*/
'use strict';
type Atom = number | bool | Object | Array<?Atom>;
export type StyleObj = Atom | Array<?StyleObj>;

View File

@ -14,8 +14,7 @@
var StyleSheetRegistry = require('StyleSheetRegistry'); var StyleSheetRegistry = require('StyleSheetRegistry');
var invariant = require('invariant'); var invariant = require('invariant');
type Atom = number | bool | Object | Array<?Atom> import type { StyleObj } from 'StyleSheetTypes';
type StyleObj = Atom | Array<?StyleObj>
function getStyle(style) { function getStyle(style) {
if (typeof style === 'number') { if (typeof style === 'number') {