11import { Component } from 'react' ;
2- import { render } from 'react-universal-interface' ;
32import { noop } from '../util' ;
43
54export interface ILifecyclesProps {
6- [ key : string ] : any ;
7- willMount ?: ( props ) => void ;
85 didMount ?: ( props ) => void ;
9- willReceiveProps ?: ( nextProps , props ) => void ;
106 shouldUpdate ?: ( nextProps , props ) => boolean ;
11- willUpdate ?: ( nextProps , props ) => void ;
12- didUpdate ?: ( props , prevProps ) => void ;
7+ getSnapshotBeforeUpdate ?: ( prevProps , props ) => any ;
8+ didUpdate ?: ( props , prevProps , snapshot ) => void ;
139 willUnmount ?: ( props ) => void ;
1410 didCatch ?: ( error , info , props ) => void ;
11+ [ key : string ] : any ;
1512}
1613
1714export class Lifecycles extends Component < ILifecyclesProps , { } > {
18- static defaultProp = {
19- willMount : noop ,
15+ static defaultProps = {
2016 didMount : noop ,
21- willReceiveProps : noop ,
2217 shouldUpdate : noop ,
23- willUpdate : noop ,
18+ getSnapshotBeforeUpdate : noop ,
2419 didUpdate : noop ,
2520 willUnmount : noop ,
2621 didCatch : noop ,
2722 } ;
2823
29- componentWillMount ( ) {
30- return this . props . willMount ( this . props ) ;
31- }
32-
3324 componentDidMount ( ) {
3425 return this . props . didMount ( this . props ) ;
3526 }
3627
37- componentWillReceiveProps ( nextProps ) {
38- return this . props . willReceiveProps ( nextProps , this . props ) ;
39- }
40-
4128 shouldComponentUpdate ( nextProps ) {
42- return this . props . shouldUpdate ( nextProps , this . props ) ;
29+ const fn = this . props . shouldUpdate ;
30+ return fn ? fn ( nextProps , this . props ) : true ;
4331 }
4432
45- componentWillUpdate ( nextProps ) {
46- return this . props . willUpdate ( nextProps , this . props ) ;
33+ getSnapshotBeforeUpdate ( prevProps ) {
34+ return this . props . getSnapshotBeforeUpdate ( prevProps , this . props ) ;
4735 }
4836
49- componentDidUpdate ( prevProps ) {
50- return this . props . didUpdate ( this . props , prevProps ) ;
37+ componentDidUpdate ( prevProps , prevState , snapshot ) {
38+ return this . props . didUpdate ( this . props , prevProps , snapshot ) ;
5139 }
5240
5341 componentWillUnmount ( ) {
@@ -59,6 +47,6 @@ export class Lifecycles extends Component<ILifecyclesProps, {}> {
5947 }
6048
6149 render ( ) {
62- return render ( this . props , null ) ;
50+ return this . props . children ;
6351 }
6452}
0 commit comments