flowify a few more Libraries

This commit is contained in:
Basil Hosmer 2015-03-26 10:06:50 -07:00
parent 7e02a1e111
commit 030b264eb4
9 changed files with 57 additions and 23 deletions

View File

@ -11,14 +11,18 @@
*/ */
'use strict'; 'use strict';
var POPAnimation = require('POPAnimation'); var POPAnimationOrNull = require('POPAnimation');
if (!POPAnimation) { if (!POPAnimationOrNull) {
// POP animation isn't available in the OSS fork - this is a temporary // POP animation isn't available in the OSS fork - this is a temporary
// workaround to enable its availability to be determined at runtime. // workaround to enable its availability to be determined at runtime.
module.exports = (null : ?{}); module.exports = (null : ?{});
} else { } else {
// At this point, POPAnimationOrNull is guaranteed to be
// non-null. Bring it local to preserve type refinement.
var POPAnimation = POPAnimationOrNull;
var invariant = require('invariant'); var invariant = require('invariant');
var warning = require('warning'); var warning = require('warning');

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule POPAnimation * @providesModule POPAnimation
* @flow
*/ */
'use strict'; 'use strict';
@ -14,7 +15,7 @@ var RCTPOPAnimationManager = require('NativeModules').POPAnimationManager;
if (!RCTPOPAnimationManager) { if (!RCTPOPAnimationManager) {
// POP animation isn't available in the OSS fork - this is a temporary // POP animation isn't available in the OSS fork - this is a temporary
// workaround to enable its availability to be determined at runtime. // workaround to enable its availability to be determined at runtime.
module.exports = null; module.exports = (null: ?Object);
} else { } else {
var ReactPropTypes = require('ReactPropTypes'); var ReactPropTypes = require('ReactPropTypes');
@ -64,6 +65,20 @@ var Types = {
spring: RCTTypes.spring, spring: RCTTypes.spring,
}; };
type Attrs = {
type?: $Enum<typeof Types>;
property?: $Enum<typeof Properties>;
fromValue?: any;
toValue?: any;
duration?: any;
velocity?: any;
deceleration?: any;
springBounciness?: any;
dynamicsFriction?: any;
dynamicsMass?: any;
dynamicsTension?: any;
}
var POPAnimation = { var POPAnimation = {
Types: Types, Types: Types,
Properties: Properties, Properties: Properties,
@ -83,11 +98,11 @@ var POPAnimation = {
}), }),
lastUsedTag: 0, lastUsedTag: 0,
allocateTagForAnimation: function() { allocateTagForAnimation: function(): number {
return ++this.lastUsedTag; return ++this.lastUsedTag;
}, },
createAnimation: function(typeName, attrs) { createAnimation: function(typeName: number, attrs: Attrs): number {
var tag = this.allocateTagForAnimation(); var tag = this.allocateTagForAnimation();
if (__DEV__) { if (__DEV__) {
@ -107,35 +122,35 @@ var POPAnimation = {
return tag; return tag;
}, },
createSpringAnimation: function(attrs) { createSpringAnimation: function(attrs: Attrs): number {
return this.createAnimation(this.Types.spring, attrs); return this.createAnimation(this.Types.spring, attrs);
}, },
createDecayAnimation: function(attrs) { createDecayAnimation: function(attrs: Attrs): number {
return this.createAnimation(this.Types.decay, attrs); return this.createAnimation(this.Types.decay, attrs);
}, },
createLinearAnimation: function(attrs) { createLinearAnimation: function(attrs: Attrs): number {
return this.createAnimation(this.Types.linear, attrs); return this.createAnimation(this.Types.linear, attrs);
}, },
createEaseInAnimation: function(attrs) { createEaseInAnimation: function(attrs: Attrs): number {
return this.createAnimation(this.Types.easeIn, attrs); return this.createAnimation(this.Types.easeIn, attrs);
}, },
createEaseOutAnimation: function(attrs) { createEaseOutAnimation: function(attrs: Attrs): number {
return this.createAnimation(this.Types.easeOut, attrs); return this.createAnimation(this.Types.easeOut, attrs);
}, },
createEaseInEaseOutAnimation: function(attrs) { createEaseInEaseOutAnimation: function(attrs: Attrs): number {
return this.createAnimation(this.Types.easeInEaseOut, attrs); return this.createAnimation(this.Types.easeInEaseOut, attrs);
}, },
addAnimation: function(nodeHandle, anim, callback) { addAnimation: function(nodeHandle: any, anim: number, callback: Function) {
RCTPOPAnimationManager.addAnimation(nodeHandle, anim, callback); RCTPOPAnimationManager.addAnimation(nodeHandle, anim, callback);
}, },
removeAnimation: function(nodeHandle, anim) { removeAnimation: function(nodeHandle: any, anim: number) {
RCTPOPAnimationManager.removeAnimation(nodeHandle, anim); RCTPOPAnimationManager.removeAnimation(nodeHandle, anim);
}, },
}; };

View File

@ -37,7 +37,8 @@ var Geolocation = {
getCurrentPosition: function( getCurrentPosition: function(
geo_success: Function, geo_success: Function,
geo_error?: Function, geo_error?: Function,
geo_options?: Object) { geo_options?: Object
) {
invariant( invariant(
typeof geo_success === 'function', typeof geo_success === 'function',
'Must provide a valid geo_success callback.' 'Must provide a valid geo_success callback.'

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule Image * @providesModule Image
* @flow
*/ */
'use strict'; 'use strict';
@ -106,7 +107,9 @@ var Image = React.createClass({
render: function() { render: function() {
var style = flattenStyle([styles.base, this.props.style]); var style = flattenStyle([styles.base, this.props.style]);
invariant(style, "style must be initialized");
var source = this.props.source; var source = this.props.source;
invariant(source, "source must be initialized");
var isNetwork = source.uri && source.uri.match(/^https?:/); var isNetwork = source.uri && source.uri.match(/^https?:/);
invariant( invariant(
!(isNetwork && source.isStatic), !(isNetwork && source.isStatic),

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ImageResizeMode * @providesModule ImageResizeMode
* @flow
*/ */
'use strict'; 'use strict';

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ImageStylePropTypes * @providesModule ImageStylePropTypes
* @flow
*/ */
'use strict'; 'use strict';
@ -39,8 +40,8 @@ var unsupportedProps = Object.keys({
paddingHorizontal: null, paddingHorizontal: null,
}); });
for (var key in unsupportedProps) { for (var i = 0; i < unsupportedProps.length; i++) {
delete ImageStylePropTypes[key]; delete ImageStylePropTypes[unsupportedProps[i]];
} }
module.exports = ImageStylePropTypes; module.exports = ImageStylePropTypes;

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule InteractionManager * @providesModule InteractionManager
* @flow
*/ */
'use strict'; 'use strict';
@ -70,7 +71,7 @@ var InteractionManager = {
/** /**
* Schedule a function to run after all interactions have completed. * Schedule a function to run after all interactions have completed.
*/ */
runAfterInteractions(callback) { runAfterInteractions(callback: Function) {
invariant( invariant(
typeof callback === 'function', typeof callback === 'function',
'Must specify a function to schedule.' 'Must specify a function to schedule.'
@ -82,7 +83,7 @@ var InteractionManager = {
/** /**
* Notify manager that an interaction has started. * Notify manager that an interaction has started.
*/ */
createInteractionHandle() { createInteractionHandle(): number {
scheduleUpdate(); scheduleUpdate();
var handle = ++_inc; var handle = ++_inc;
_addInteractionSet.add(handle); _addInteractionSet.add(handle);
@ -92,7 +93,7 @@ var InteractionManager = {
/** /**
* Notify manager that an interaction has completed. * Notify manager that an interaction has completed.
*/ */
clearInteractionHandle(handle) { clearInteractionHandle(handle: number) {
invariant( invariant(
!!handle, !!handle,
'Must provide a handle to clear.' 'Must provide a handle to clear.'

View File

@ -2,6 +2,7 @@
* Copyright 2004-present Facebook. All Rights Reserved. * Copyright 2004-present Facebook. All Rights Reserved.
* *
* @providesModule InteractionMixin * @providesModule InteractionMixin
* @flow
*/ */
'use strict'; 'use strict';
@ -21,7 +22,7 @@ var InteractionMixin = {
} }
}, },
_interactionMixinHandles: [], _interactionMixinHandles: ([]: Array<number>),
createInteractionHandle: function() { createInteractionHandle: function() {
var handle = InteractionManager.createInteractionHandle(); var handle = InteractionManager.createInteractionHandle();
@ -29,7 +30,7 @@ var InteractionMixin = {
return handle; return handle;
}, },
clearInteractionHandle: function(clearHandle) { clearInteractionHandle: function(clearHandle: number) {
InteractionManager.clearInteractionHandle(clearHandle); InteractionManager.clearInteractionHandle(clearHandle);
this._interactionMixinHandles = this._interactionMixinHandles.filter( this._interactionMixinHandles = this._interactionMixinHandles.filter(
handle => handle !== clearHandle handle => handle !== clearHandle
@ -41,7 +42,7 @@ var InteractionMixin = {
* *
* @param {function} callback * @param {function} callback
*/ */
runAfterInteractions: function(callback) { runAfterInteractions: function(callback: Function) {
InteractionManager.runAfterInteractions(callback); InteractionManager.runAfterInteractions(callback);
}, },
}; };

View File

@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
* *
* @providesModule ExceptionsManager * @providesModule ExceptionsManager
* @flow
*/ */
'use strict'; 'use strict';
@ -18,7 +19,13 @@ var parseErrorStack = require('parseErrorStack');
var sourceMapPromise; var sourceMapPromise;
function handleException(e) { type Exception = {
sourceURL: string;
line: number;
message: string;
}
function handleException(e: Exception) {
var stack = parseErrorStack(e); var stack = parseErrorStack(e);
console.error( console.error(
'Error: ' + 'Error: ' +