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';
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
// workaround to enable its availability to be determined at runtime.
module.exports = (null : ?{});
} 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 warning = require('warning');

View File

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

View File

@ -37,7 +37,8 @@ var Geolocation = {
getCurrentPosition: function(
geo_success: Function,
geo_error?: Function,
geo_options?: Object) {
geo_options?: Object
) {
invariant(
typeof geo_success === 'function',
'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.
*
* @providesModule Image
* @flow
*/
'use strict';
@ -106,7 +107,9 @@ var Image = React.createClass({
render: function() {
var style = flattenStyle([styles.base, this.props.style]);
invariant(style, "style must be initialized");
var source = this.props.source;
invariant(source, "source must be initialized");
var isNetwork = source.uri && source.uri.match(/^https?:/);
invariant(
!(isNetwork && source.isStatic),

View File

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

View File

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

View File

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

View File

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

View File

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