@samitouri / QOS-React / commits / 3a856091be

Add some Flow and get rid of the typecheck annotations

Sebastian Markbage committed Nov 16, 2016 at 15:10 UTC 3a856091be18f8ac94f2e813d7a834ac9482521b
5 files changed +49 -73
src/renderers/dom/fiber/ReactDOMFiberComponent.js
+21 -46
@@ -14,6 +14,8 @@
14
15 'use strict';
16
17 +import type { Fiber } from 'ReactFiber';
18 +
19 var CSSPropertyOperations = require('CSSPropertyOperations');
20 var DOMNamespaces = require('DOMNamespaces');
21 var DOMProperty = require('DOMProperty');
@@ -68,11 +70,7 @@ function getDeclarationErrorAddendum(internalInstance) {
70 return '';
71 }
72
71 -/**
72 - * @param {object} component
73 - * @param {?object} props
74 - */
75 -function assertValidProps(component, props) {
73 +function assertValidProps(component : Fiber, props : ?Object) {
74 if (!props) {
75 return;
76 }
@@ -297,9 +295,10 @@ var newlineEatingTags = {
295 // For HTML, certain tags cannot have children. This has the same purpose as
296 // `omittedCloseTags` except that `menuitem` should still have its closing tag.
297
300 -var voidElementTags = Object.assign({
298 +var voidElementTags = {
299 'menuitem': true,
302 -}, omittedCloseTags);
300 + ...omittedCloseTags
301 +};
302
303 // We accept any tag to be rendered but since this gets injected into arbitrary
304 // HTML, we want to make sure that it's a safe tag.
@@ -330,18 +329,13 @@ function isCustomComponent(tagName, props) {
329 * TODO: Benchmark the effects of putting workInProgress at the top since 99% of props
330 * do not change for a given reconciliation.
331 * TODO: Benchmark areas that can be improved with caching.
333 - *
334 - * @private
335 - * @param {object} lastProps
336 - * @param {object} nextProps
337 - * @param {?DOMElement} node
332 */
333 function updateDOMProperties(
340 - workInProgress,
341 - lastProps,
342 - nextProps,
343 - isCustomComponentTag
344 -) {
334 + workInProgress : Fiber,
335 + lastProps : null | Object,
336 + nextProps : Object,
337 + isCustomComponentTag : boolean
338 +) : void {
339 var propKey;
340 var styleName;
341 var styleUpdates;
@@ -476,23 +470,12 @@ function updateDOMProperties(
470
471 var ReactDOMFiberComponent = {
472
479 -
480 - /**
481 - * Generates root tag markup then recurses. This method has side effects and
482 - * is not idempotent.
483 - *
484 - * @internal
485 - * @param {?ReactDOMComponent} the parent component instance
486 - * @param {?object} info about the host container
487 - * @param {object} context
488 - * @return {string} The computed markup.
489 - */
473 mountComponent: function(
474 workInProgress : Fiber,
492 - hostParent,
493 - hostContainerInfo,
494 - context
495 - ) {
475 + hostParent : Fiber,
476 + hostContainerInfo : Object,
477 + context : Object
478 + ) : Element {
479 // validateDangerousTag(tag);
480 // workInProgress._tag = tag.toLowerCase();
481
@@ -651,20 +634,12 @@ var ReactDOMFiberComponent = {
634 return el;
635 },
636
654 -
655 - /**
656 - * Receives a next element and updates the component.
657 - *
658 - * @internal
659 - * @param {ReactElement} nextElement
660 - * @param {object} context
661 - */
662 - receiveComponent: function(workInProgress : Fiber, nextElement, context) {
663 - var prevElement = workInProgress._currentElement;
664 - workInProgress._currentElement = nextElement;
665 -
666 - var lastProps = prevElement.props;
667 - var nextProps = workInProgress._currentElement.props;
637 + receiveComponent: function(
638 + workInProgress : Fiber,
639 + nextProps : Object,
640 + context : Object
641 + ) {
642 + var lastProps = workInProgress.memoizedProps;
643
644 switch (workInProgress._tag) {
645 case 'input':
src/renderers/dom/fiber/wrappers/ReactDOMFiberInput.js
+8 -6
@@ -12,6 +12,8 @@
12
13 'use strict';
14
15 +import type { Fiber } from 'ReactFiber';
16 +
17 var DOMPropertyOperations = require('DOMPropertyOperations');
18 var ReactControlledValuePropTypes = require('ReactControlledValuePropTypes');
19 var ReactDOMComponentTree = require('ReactDOMComponentTree');
@@ -43,10 +45,10 @@ function isControlled(props) {
45 * The rendered element will be initialized as unchecked (or `defaultChecked`)
46 * with an empty value (or `defaultValue`).
47 *
46 - * @see http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
48 + * See http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
49 */
50 var ReactDOMInput = {
49 - getHostProps: function(inst, props) {
51 + getHostProps: function(inst : Fiber, props : Object) {
52 var value = props.value;
53 var checked = props.checked;
54
@@ -71,7 +73,7 @@ var ReactDOMInput = {
73 return hostProps;
74 },
75
74 - mountWrapper: function(inst, props) {
76 + mountWrapper: function(inst : Fiber, props : Object) {
77 if (__DEV__) {
78 ReactControlledValuePropTypes.checkPropTypes(
79 'input',
@@ -130,7 +132,7 @@ var ReactDOMInput = {
132 }
133 },
134
133 - updateWrapper: function(inst) {
135 + updateWrapper: function(inst : Fiber) {
136 var props = inst._currentElement.props;
137
138 if (__DEV__) {
@@ -204,7 +206,7 @@ var ReactDOMInput = {
206 }
207 },
208
207 - postMountWrapper: function(inst) {
209 + postMountWrapper: function(inst : Fiber) {
210 var props = inst._currentElement.props;
211
212 // This is in postMount because we need access to the DOM node, which is not
@@ -254,7 +256,7 @@ var ReactDOMInput = {
256 }
257 },
258
257 - restoreControlledState: function(inst) {
259 + restoreControlledState: function(inst : Fiber) {
260 ReactDOMInput.updateWrapper(inst);
261 var props = inst._currentElement.props;
262 updateNamedCousins(inst, props);
src/renderers/dom/fiber/wrappers/ReactDOMFiberOption.js
+5 -3
@@ -12,6 +12,8 @@
12
13 'use strict';
14
15 +import type { Fiber } from 'ReactFiber';
16 +
17 var React = require('React');
18 var ReactDOMComponentTree = require('ReactDOMComponentTree');
19 var ReactDOMSelect = require('ReactDOMSelect');
@@ -46,7 +48,7 @@ function flattenChildren(children) {
48 * Implements an <option> host component that warns when `selected` is set.
49 */
50 var ReactDOMOption = {
49 - mountWrapper: function(inst, props, hostParent) {
51 + mountWrapper: function(inst : Fiber, props : Object, hostParent : Fiber) {
52 // TODO (yungsters): Remove support for `selected` in <option>.
53 if (__DEV__) {
54 warning(
@@ -97,7 +99,7 @@ var ReactDOMOption = {
99 inst._wrapperState = {selected: selected};
100 },
101
100 - postMountWrapper: function(inst) {
102 + postMountWrapper: function(inst : Fiber) {
103 // value="" should make a value attribute (#6219)
104 var props = inst._currentElement.props;
105 if (props.value != null) {
@@ -106,7 +108,7 @@ var ReactDOMOption = {
108 }
109 },
110
109 - getHostProps: function(inst, props) {
111 + getHostProps: function(inst : Fiber, props : Object) {
112 var hostProps = Object.assign({selected: undefined, children: undefined}, props);
113
114 // Read state only from initial mount because <select> updates value
src/renderers/dom/fiber/wrappers/ReactDOMFiberSelect.js
+8 -13
@@ -12,6 +12,8 @@
12
13 'use strict';
14
15 +import type { Fiber } from 'ReactFiber';
16 +
17 var ReactControlledValuePropTypes = require('ReactControlledValuePropTypes');
18 var ReactDOMComponentTree = require('ReactDOMComponentTree');
19
@@ -33,7 +35,6 @@ var valuePropNames = ['value', 'defaultValue'];
35
36 /**
37 * Validation function for `value` and `defaultValue`.
36 - * @private
38 */
39 function checkSelectPropTypes(inst, props) {
40 var owner = inst._currentElement._owner;
@@ -69,13 +70,7 @@ function checkSelectPropTypes(inst, props) {
70 }
71 }
72
72 -/**
73 - * @param {ReactDOMComponent} inst
74 - * @param {boolean} multiple
75 - * @param {*} propValue A stringable (with `multiple`, a list of stringables).
76 - * @private
77 - */
78 -function updateOptions(inst, multiple, propValue) {
73 +function updateOptions(inst : Fiber, multiple : boolean, propValue : string | Array<string>) {
74 var options = ReactDOMComponentTree.getNodeFromInstance(inst).options;
75
76 if (multiple) {
@@ -121,13 +116,13 @@ function updateOptions(inst, multiple, propValue) {
116 * selected.
117 */
118 var ReactDOMSelect = {
124 - getHostProps: function(inst, props) {
119 + getHostProps: function(inst : Fiber, props : Object) {
120 return Object.assign({}, props, {
121 value: undefined,
122 });
123 },
124
130 - mountWrapper: function(inst, props) {
125 + mountWrapper: function(inst : Fiber, props : Object) {
126 if (__DEV__) {
127 checkSelectPropTypes(inst, props);
128 }
@@ -155,13 +150,13 @@ var ReactDOMSelect = {
150 }
151 },
152
158 - getSelectValueContext: function(inst) {
153 + getSelectValueContext: function(inst : Fiber) {
154 // ReactDOMOption looks at this initial value so the initial generated
155 // markup has correct `selected` attributes
156 return inst._wrapperState.initialValue;
157 },
158
164 - postUpdateWrapper: function(inst) {
159 + postUpdateWrapper: function(inst : Fiber) {
160 var props = inst._currentElement.props;
161
162 // After the initial mount, we control selected-ness manually so don't pass
@@ -185,7 +180,7 @@ var ReactDOMSelect = {
180 }
181 },
182
188 - restoreControlledState: function(inst) {
183 + restoreControlledState: function(inst : Fiber) {
184 var props = inst._currentElement.props;
185 var value = props.value;
186
src/renderers/dom/fiber/wrappers/ReactDOMFiberTextarea.js
+7 -5
@@ -12,6 +12,8 @@
12
13 'use strict';
14
15 +import type { Fiber } from 'ReactFiber';
16 +
17 var ReactControlledValuePropTypes = require('ReactControlledValuePropTypes');
18 var ReactDOMComponentTree = require('ReactDOMComponentTree');
19
@@ -36,7 +38,7 @@ var didWarnValDefaultVal = false;
38 * `defaultValue` if specified, or the children content (deprecated).
39 */
40 var ReactDOMTextarea = {
39 - getHostProps: function(inst, props) {
41 + getHostProps: function(inst : Fiber, props : Object) {
42 invariant(
43 props.dangerouslySetInnerHTML == null,
44 '`dangerouslySetInnerHTML` does not make sense on <textarea>.'
@@ -56,7 +58,7 @@ var ReactDOMTextarea = {
58 return hostProps;
59 },
60
59 - mountWrapper: function(inst, props) {
61 + mountWrapper: function(inst : Fiber, props : Object) {
62 if (__DEV__) {
63 ReactControlledValuePropTypes.checkPropTypes(
64 'textarea',
@@ -122,7 +124,7 @@ var ReactDOMTextarea = {
124 };
125 },
126
125 - updateWrapper: function(inst) {
127 + updateWrapper: function(inst : Fiber) {
128 var props = inst._currentElement.props;
129
130 var node = ReactDOMComponentTree.getNodeFromInstance(inst);
@@ -145,7 +147,7 @@ var ReactDOMTextarea = {
147 }
148 },
149
148 - postMountWrapper: function(inst) {
150 + postMountWrapper: function(inst : Fiber) {
151 // This is in postMount because we need access to the DOM node, which is not
152 // available until after the component has mounted.
153 var node = ReactDOMComponentTree.getNodeFromInstance(inst);
@@ -160,7 +162,7 @@ var ReactDOMTextarea = {
162 }
163 },
164
163 - restoreControlledState: function(inst) {
165 + restoreControlledState: function(inst : Fiber) {
166 // DOM component is still mounted; update
167 ReactDOMTextarea.updateWrapper(inst);
168 },