Skip to content

Commit

Permalink
Added new React lifecycles for upcomign version 16.3
Browse files Browse the repository at this point in the history
Summary:
Codemod to rename unsafe lifecycles (D7220433) hit a couple of Flow errors due to the fact that Flow wasn't yet aware of these new lifecycles. So I took a stab at adding them. :)

More information available here: https://deploy-preview-596--reactjs.netlify.com/blog/2018/03/15/update-on-async-rendering.html

Reviewed By: samwgoldman

Differential Revision: D7221244

fbshipit-source-id: 162bbf0c2b5f73b17b7abfa3097fd35b12d6ebd2
  • Loading branch information
Brian Vaughn authored and facebook-github-bot committed Mar 10, 2018
1 parent 3619824 commit cd8fdcd
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 250 deletions.
10 changes: 10 additions & 0 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ declare class React$Component<Props, State = void> {
constructor(props?: Props, context?: any): void;
render(): React$Node;
componentWillMount(): mixed;
UNSAFE_componentWillMount(): mixed;
componentDidMount(): mixed;
componentWillReceiveProps(
nextProps: Props,
nextContext: any,
): mixed;
UNSAFE_componentWillReceiveProps(
nextProps: Props,
nextContext: any,
): mixed;
shouldComponentUpdate(
nextProps: Props,
nextState: State,
Expand All @@ -58,6 +63,11 @@ declare class React$Component<Props, State = void> {
nextState: State,
nextContext: any,
): mixed;
UNSAFE_componentWillUpdate(
nextProps: Props,
nextState: State,
nextContext: any,
): mixed;
componentDidUpdate(
prevProps: Props,
prevState: State,
Expand Down
8 changes: 4 additions & 4 deletions tests/getters_and_setters/getters_and_setters.exp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ References:
react.js:17:13
17| (<Example a="bad" />); // error: number ~> string
^^^^^ [1]
<BUILTINS>/react.js:294:36
294| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:304:36
304| number: React$PropType$Primitive<number>;
^^^^^^ [2]


Expand All @@ -506,8 +506,8 @@ References:
react.js:18:20
18| (<Example a={0} c={0} />); // error: number ~> string
^ [1]
<BUILTINS>/react.js:296:36
296| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:306:36
306| string: React$PropType$Primitive<string>;
^^^^^^ [2]


Expand Down
36 changes: 18 additions & 18 deletions tests/more_react/more_react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ Cannot call `checkPropTypes` because function [1] requires another argument.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:190:41
<BUILTINS>/react.js:200:41
v---
190| declare export function checkPropTypes<V>(
191| propTypes: $Subtype<{[_: $Keys<V>]: ReactPropsCheckType}>,
192| values: V,
193| location: string,
194| componentName: string,
195| getStack: ?(() => ?string)
196| ) : void;
200| declare export function checkPropTypes<V>(
201| propTypes: $Subtype<{[_: $Keys<V>]: ReactPropsCheckType}>,
202| values: V,
203| location: string,
204| componentName: string,
205| getStack: ?(() => ?string)
206| ) : void;
-------^ [1]


Expand All @@ -79,15 +79,15 @@ Cannot call `checkPropTypes` because function [1] requires another argument.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:190:41
<BUILTINS>/react.js:200:41
v---
190| declare export function checkPropTypes<V>(
191| propTypes: $Subtype<{[_: $Keys<V>]: ReactPropsCheckType}>,
192| values: V,
193| location: string,
194| componentName: string,
195| getStack: ?(() => ?string)
196| ) : void;
200| declare export function checkPropTypes<V>(
201| propTypes: $Subtype<{[_: $Keys<V>]: ReactPropsCheckType}>,
202| values: V,
203| location: string,
204| componentName: string,
205| getStack: ?(() => ?string)
206| ) : void;
-------^ [1]


Expand All @@ -113,8 +113,8 @@ References:
checkPropTypes.js:12:91
12| checkPropTypes({ foo: PropTypes.string }, { foo: 'foo' }, 'value', 'TestComponent', () => 123); // error: number ~> string
^^^ [1]
<BUILTINS>/react.js:195:24
195| getStack: ?(() => ?string)
<BUILTINS>/react.js:205:24
205| getStack: ?(() => ?string)
^^^^^^ [2]


Expand Down
66 changes: 33 additions & 33 deletions tests/new_react/new_react.exp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ References:
classes.js:39:15
39| var foo: $jsx<number> = <Foo/>;
^^^^^^ [1]
<BUILTINS>/react.js:149:5
149| | string
<BUILTINS>/react.js:159:5
159| | string
^^^^^^ [2]


Expand All @@ -189,8 +189,8 @@ Cannot assign `this.props.x` to `_` because number [1] is incompatible with stri
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:294:36
294| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:304:36
304| number: React$PropType$Primitive<number>;
^^^^^^ [1]
classes.js:57:12
57| var _: string = this.props.x;
Expand Down Expand Up @@ -316,8 +316,8 @@ References:
classes.js:79:22
79| var foo_legacy: $jsx<number> = <FooLegacy/>;
^^^^^^ [1]
<BUILTINS>/react.js:149:5
149| | string
<BUILTINS>/react.js:159:5
159| | string
^^^^^^ [2]


Expand Down Expand Up @@ -388,8 +388,8 @@ Cannot assign `this.props.z` to `qux` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:294:36
294| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:304:36
304| number: React$PropType$Primitive<number>;
^^^^^^ [1]
new_react.js:19:18
19| var qux: string = this.props.z;
Expand All @@ -405,8 +405,8 @@ Cannot assign `this.props.x` to `w` because string [1] is incompatible with numb
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:296:36
296| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:306:36
306| string: React$PropType$Primitive<string>;
^^^^^^ [1]
new_react.js:20:15
20| var w:number = this.props.x;
Expand Down Expand Up @@ -439,8 +439,8 @@ References:
new_react.js:29:23
29| var element = <C x = {0}/>;
^ [1]
<BUILTINS>/react.js:296:36
296| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:306:36
306| string: React$PropType$Primitive<string>;
^^^^^^ [2]


Expand Down Expand Up @@ -475,14 +475,14 @@ Cannot assign `C.displayName` to `x` because:
^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:73:24
73| static displayName?: ?string;
<BUILTINS>/react.js:83:24
83| static displayName?: ?string;
^^^^^^^ [1]
new_react.js:32:8
32| var x: number = C.displayName;
^^^^^^ [2]
<BUILTINS>/react.js:73:25
73| static displayName?: ?string;
<BUILTINS>/react.js:83:25
83| static displayName?: ?string;
^^^^^^ [3]


Expand Down Expand Up @@ -545,8 +545,8 @@ Cannot assign `this.props.x` to `a` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:296:36
296| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:306:36
306| string: React$PropType$Primitive<string>;
^^^^^^ [1]
props.js:14:16
14| var a: number = this.props.x; // error
Expand Down Expand Up @@ -582,8 +582,8 @@ Cannot assign `this.props.z` to `c` because:
^^^^^^^^^^^^

References:
<BUILTINS>/react.js:294:36
294| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:304:36
304| number: React$PropType$Primitive<number>;
^^^^^^ [1]
props.js:16:16
16| var c: string = this.props.z; // error
Expand All @@ -604,14 +604,14 @@ References:
props.js:20:29
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [1]
<BUILTINS>/react.js:296:36
296| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:306:36
306| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props.js:20:49
20| var element = <TestProps x={false} y={false} z={false} />; // 3 errors
^^^^^ [3]
<BUILTINS>/react.js:294:36
294| number: React$PropType$Primitive<number>;
<BUILTINS>/react.js:304:36
304| number: React$PropType$Primitive<number>;
^^^^^^ [4]


Expand Down Expand Up @@ -668,8 +668,8 @@ References:
props2.js:9:41
9| getInitialState: function(): { bar: number } {
^^^^^^ [1]
<BUILTINS>/react.js:296:36
296| string: React$PropType$Primitive<string>;
<BUILTINS>/react.js:306:36
306| string: React$PropType$Primitive<string>;
^^^^^^ [2]
props2.js:15:42
15| return <C {...this.state} foo = {0} />;
Expand All @@ -685,8 +685,8 @@ Cannot get `React.PropTypes.imaginaryType` because property `imaginaryType` is m
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:185:33
185| declare export var PropTypes: ReactPropTypes;
<BUILTINS>/react.js:195:33
195| declare export var PropTypes: ReactPropTypes;
^^^^^^^^^^^^^^ [1]


Expand All @@ -700,12 +700,12 @@ Cannot get `React.PropTypes.string.inRequired` because property `inRequired` is
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

References:
<BUILTINS>/react.js:270:39
<BUILTINS>/react.js:280:39
v
270| type ReactPropsChainableTypeChecker = {
271| isRequired: ReactPropsCheckType;
272| (props: any, propName: string, componentName: string, href?: string): ?Error;
273| };
280| type ReactPropsChainableTypeChecker = {
281| isRequired: ReactPropsCheckType;
282| (props: any, propName: string, componentName: string, href?: string): ?Error;
283| };
^ [1]


Expand Down
Loading

0 comments on commit cd8fdcd

Please sign in to comment.