[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;
function getStyleFromScore(score: number): {color: string} {
import type { StyleObj } from 'StyleSheetTypes';
function getStyleFromScore(score: number): StyleObj {
if (score < 0) {
return styles.noScore;
}

View File

@ -72,7 +72,9 @@ function setupDevtools() {
}
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 {
data = JSON.parse(evt.data);
} catch (e) {

View File

@ -138,6 +138,23 @@ type ConnectivityStateAndroid = $Enum<{
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 = {
addEventListener: function (
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') {
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();
NetInfo.isConnected = {
addEventListener: function (
eventName: ChangeEventName,
handler: Function
): void {
var listener = (connection) => {
handler(_isConnected(connection));
};
_isConnectedSubscriptions.set(handler, listener);
NetInfo.addEventListener(
eventName,
listener
);
fetch: function(): Promise {
return NetInfo.fetch().then(
(connection) => _isConnected(connection)
);
},
},
removeEventListener: function(
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)
);
},
isConnectionMetered: ({}: {} | (callback:Function) => void),
};
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 invariant = require('invariant');
type Atom = number | bool | Object | Array<?Atom>
type StyleObj = Atom | Array<?StyleObj>
import type { StyleObj } from 'StyleSheetTypes';
function getStyle(style) {
if (typeof style === 'number') {