Permalink
Browse files

Fix all flow type errors.

  • Loading branch information...
1 parent fd70426 commit 7af81aabdd7bff5bda5da49e93fceca07ee8234c @oliverzheng committed May 15, 2015
View
@@ -1,5 +1,6 @@
[ignore]
.*/build/.*
+.*/buildtest/.*
[options]
module.system=node
@@ -7,8 +7,8 @@ var RadioListComponent = require('./RadioListComponent');
var Options = require('../how/Options');
class AlignmentComponent extends React.Component {
- _horizontal: RadioListComponent;
- _vertical: RadioListComponent;
+ _horizontal: RadioListComponent<Options.HorizontalAlignment>;
+ _vertical: RadioListComponent<Options.VerticalAlignment>;
getHorizontalAlignment(): ?Options.HorizontalAlignment {
return this._horizontal.getValue();
@@ -10,7 +10,7 @@ class CodeComponent extends React.Component {
noMethod: bool;
};
- constructor(props) {
+ constructor(props: mixed) {
super(props);
this.state = {
method: null,
@@ -11,22 +11,26 @@ var RadioListComponent = require('./RadioListComponent');
var Options = require('../how/Options');
-class ContentType {}
+class ContentType {
+ static TEXT: ContentType;
+ static IMAGE: ContentType;
+ static DIV: ContentType;
+}
ContentType.TEXT = new ContentType();
ContentType.IMAGE = new ContentType();
ContentType.DIV = new ContentType();
class ContentComponent extends React.Component {
state: {
contentType: ?ContentType;
- textLinesKnown: bool;
+ textLines: ?number;
};
_divSize: ?DivSizeComponent;
_textLines: ?TextLinesComponent;
_textFontSize: ?TextFontSizeComponent;
_textLineHeight: ?TextLineHeightComponent;
- constructor(props) {
+ constructor(props: mixed) {
super(props);
this.state = {
contentType: null,
@@ -78,7 +82,7 @@ class ContentComponent extends React.Component {
if (this.state.textLines === 1) {
textFontSize =
<TextFontSizeComponent ref={(c) => this._textFontSize = c} />;
- } else if (this.state.textLines > 1) {
+ } else if (this.state.textLines != null && this.state.textLines > 1) {
textLineHeight =
<TextLineHeightComponent ref={(c) => this._textLineHeight = c} />;
}
@@ -18,7 +18,7 @@ class DivSizeComponent extends React.Component {
return this._height.getLength();
}
- _handleWidthKnown(known) {
+ _handleWidthKnown(known: bool) {
if (!known) {
if (this.props.onWidthChange) {
this.props.onWidthChange(null);
@@ -29,7 +29,7 @@ class DivSizeComponent extends React.Component {
}
}
- _handleHeightKnown(known) {
+ _handleHeightKnown(known: bool) {
if (!known) {
if (this.props.onHeightChange) {
this.props.onHeightChange(null);
@@ -13,7 +13,7 @@ class LengthComponent extends React.Component {
_valueInput: React.Component;
_radioList: RadioListComponent;
- constructor(props) {
+ constructor(props: mixed) {
super(props);
this.state = { value: null, type: null };
}
@@ -1,5 +1,7 @@
/** @flow */
+var invariant = require('invariant');
+
var React = require('react');
var AlignmentComponent = require('./AlignmentComponent');
var BrowserSupportComponent = require('./BrowserSupportComponent');
@@ -17,19 +19,27 @@ class OptionsComponent extends React.Component {
_browserSupport: BrowserSupportComponent;
getContent(): Options.Content {
- return this._content.getContent();
+ var content = this._content.getContent();
+ invariant(content, 'No content');
+ return content;
}
getContainer(): Options.Container {
- return this._container.getContainer();
+ var container = this._container.getContainer();
+ invariant(container, 'No container');
+ return container;
}
getHorizontalAlignment(): Options.HorizontalAlignment {
- return this._alignment.getHorizontalAlignment();
+ var alignment = this._alignment.getHorizontalAlignment();
+ invariant(alignment, 'No horizontal alignment');
+ return alignment;
}
getVerticalAlignment(): Options.VerticalAlignment {
- return this._alignment.getVerticalAlignment();
+ var alignment = this._alignment.getVerticalAlignment();
+ invariant(alignment, 'No vertical alignment');
+ return alignment;
}
render(): ?ReactElement {
@@ -6,7 +6,7 @@ var classnames = require('classnames');
class RadioComponent extends React.Component {
isSelected: bool;
- constructor(props) {
+ constructor(props: mixed) {
super(props);
this.state = {
isSelected: false,
@@ -4,20 +4,20 @@ var React = require('react');
var RadioComponent = require('./RadioComponent');
var classnames = require('classnames');
-class RadioListComponent extends React.Component {
+class RadioListComponent<T> extends React.Component {
state: {
selectedOption: ?RadioComponent;
};
- constructor(props) {
+ constructor(props: mixed) {
super(props);
this.state = {
selectedOption: null,
};
}
- getValue(): ?mixed {
+ getValue(): ?T {
if (this.state.selectedOption) {
return this.state.selectedOption.props.value;
}
@@ -56,7 +56,7 @@ class RadioListComponent extends React.Component {
this._selectOption(null);
}
- select(value) {
+ select(value: T) {
var childrenRefKeys = Object.keys(this.refs);
for (var i = 0; i < childrenRefKeys.length; i++) {
var child = this.refs[childrenRefKeys[i]];
@@ -11,7 +11,7 @@ class TextLinesComponent extends React.Component {
};
_linesInput: React.Component;
- constructor(props) {
+ constructor(props: mixed) {
super(props);
this.state = {
lines: null,
View
@@ -5,6 +5,11 @@ var keyMirror = require('keymirror');
class LengthType {
cssUnit: string;
+ static PIXEL: LengthType;
+ static PERCENTAGE: LengthType;
+ static EM: LengthType;
+ static AllTypes: Array<LengthType>;
+
constructor(cssUnit: string) {
this.cssUnit = cssUnit;
}
@@ -74,11 +79,17 @@ class Length {
//
// The inner container is either inline-block or block. If a paragraph of text
// is to be centered, it should be put into an inline-block first.
-type Text = {
+class Text {
fontSize: ?Length;
lines: ?number;
lineHeight: ?Length;
-};
+
+ constructor(fontSize: ?Length, lines: ?number, lineHeight: ?Length) {
+ this.fontSize = fontSize;
+ this.lines = lines;
+ this.lineHeight = lineHeight;
+ }
+}
class Content {
width: ?Length;
@@ -95,10 +106,10 @@ class Content {
var height = null;
if (lines === 1 && fontSize) {
height = new Length(fontSize.value, fontSize.lengthType);
- } else if (lines > 1 && lineHeight) {
+ } else if (lines && lines > 1 && lineHeight) {
height = new Length(lineHeight.value * lines, lineHeight.lengthType);
}
- return new Content(null, height, {fontSize, lines, lineHeight});
+ return new Content(null, height, new Text(fontSize, lines, lineHeight));
}
}
@@ -112,12 +123,20 @@ class Container {
}
}
-class HorizontalAlignment {}
+class HorizontalAlignment {
+ static LEFT: HorizontalAlignment;
+ static CENTER: HorizontalAlignment;
+ static RIGHT: HorizontalAlignment;
+}
HorizontalAlignment.LEFT = new HorizontalAlignment();
HorizontalAlignment.CENTER = new HorizontalAlignment();
HorizontalAlignment.RIGHT = new HorizontalAlignment();
-class VerticalAlignment {}
+class VerticalAlignment {
+ static TOP: VerticalAlignment;
+ static MIDDLE: VerticalAlignment;
+ static BOTTOM: VerticalAlignment;
+}
VerticalAlignment.TOP = new VerticalAlignment();
VerticalAlignment.MIDDLE = new VerticalAlignment();
VerticalAlignment.BOTTOM = new VerticalAlignment();
@@ -129,4 +148,5 @@ module.exports = {
VerticalAlignment,
Content,
Container,
+ Text,
};
View
@@ -25,38 +25,38 @@ function checkContainer(check: (container: Options.Container) => bool): Check {
function checkContentText(check: (text: Options.Text) => bool): Check {
return (content, container, horizontalAlignment, verticalAlignment) => {
- return check(content.text);
+ return content.text != null && check(content.text);
};
}
function requireLineHeight(
- requirement: (text: Options.Text) => bool
+ requirement: (text: Options.Length) => bool
): (obj: Options.Text) => bool {
- return (obj) => obj.lineHeight && requirement(obj.lineHeight);
+ return (obj) => obj.lineHeight != null && requirement(obj.lineHeight);
}
var requireLineHeightExists = requireLineHeight((l) => true);
function requireFontSize(
- requirement: (text: Options.Text) => bool
+ requirement: (text: Options.Length) => bool
): (obj: Options.Text) => bool {
- return (obj) => obj.fontSize && requirement(obj.fontSize);
+ return (obj) => obj.fontSize != null && requirement(obj.fontSize);
}
var requireFontSizeExists = requireFontSize((l) => true);
function requireHeight(
requirement: (length: Options.Length) => bool
): (obj: Options.Content | Options.Container) => bool {
- return (obj) => obj.height && requirement(obj.height);
+ return (obj) => obj.height != null && requirement(obj.height);
}
var requireHeightExists = requireHeight((l) => true);
function requireWidth(
requirement: (length: Options.Length) => bool
): (obj: Options.Content | Options.Container) => bool {
- return (obj) => obj.width && requirement(obj.width);
+ return (obj) => obj.width != null && requirement(obj.width);
}
var requireWidthExists = requireWidth((w) => true);
@@ -77,7 +77,7 @@ class Method {
return content;
}
- getTextContent(): ?ReactElement {
+ getTextContent(): mixed {
if (this._addIDs) {
// TODO rename addIDs to "isTest" or something
// These IIs have the least variance in font rendering. Even if the fonts
@@ -50,6 +50,7 @@ class PixelHeightContainerContentPaddingMethod extends Method {
} else if (verticalAlignment === Options.VerticalAlignment.BOTTOM) {
paddingTop = heightDiff;
}
+ invariant(paddingTop, 'typechecker');
parentStyles.paddingTop = paddingTop.toString();
}
@@ -1,5 +1,7 @@
/* @flow */
+var invariant = require('invariant');
+
var Method = require('./Method');
var Requirement = require('./Requirement');
var Options = require('../Options');
@@ -21,7 +23,7 @@ class SingleLineTextLineHeightMethod extends Method {
),
new Requirement(
'Content has single line of text',
- c.checkContent((content) => content.text && content.text.lines === 1)
+ c.checkContentText((text) => text.lines === 1)
),
Requirement.any([
new Requirement(
@@ -59,13 +61,21 @@ class SingleLineTextLineHeightMethod extends Method {
}
if (verticalAlignment !== Options.VerticalAlignment.TOP) {
+ var containerHeight = container.height;
+ invariant(containerHeight, 'Must have container height');
+
if (verticalAlignment === Options.VerticalAlignment.MIDDLE) {
- styles.lineHeight = container.height.toString();
+ styles.lineHeight = containerHeight.toString();
} else if (verticalAlignment === Options.VerticalAlignment.BOTTOM) {
+ var text = content.text;
+ invariant(text, 'Must have content text');
+ var fontSize = text.fontSize;
+ invariant(fontSize, 'Must have content text font size');
+
styles.lineHeight =
- container.height.multiply(2).
- subtract(content.text.fontSize);
- styles.height = container.height.toString();
+ containerHeight.multiply(2).
+ subtract(fontSize);
+ styles.height = containerHeight.toString();
}
}
return (
View
@@ -55,21 +55,21 @@
"react": "global:React"
},
"dependencies": {
- "fastclick": "^1.0.3",
- "keymirror": "^0.1.1",
- "shortid": "^2.1.3",
"browserify-shim": "^3.8.3",
- "uglifycss": "0.0.13",
- "wd": "^0.3.11",
- "wd-screenshot": "^0.1.0",
+ "chai": "^2.3.0",
+ "chai-as-promised": "^5.0.0",
"colors": "^1.0.3",
+ "fastclick": "^1.0.3",
+ "gm": "^1.17.0",
+ "js-combinatorics": "^0.4.0",
"js-string-escape": "^1.0.0",
+ "keymirror": "^0.1.1",
"mocha": "^2.2.4",
- "js-combinatorics": "^0.4.0",
"q": "^1.3.0",
"react-tools": "^0.13.2",
- "chai": "^2.3.0",
- "chai-as-promised": "^5.0.0",
- "gm": "^1.17.0"
+ "shortid": "^2.1.3",
+ "uglifycss": "0.0.13",
+ "wd": "^0.3.11",
+ "wd-screenshot": "^0.1.0"
}
}

0 comments on commit 7af81aa

Please sign in to comment.