1- import React , { PropTypes } from 'react' ;
2- import Frame from './frame' ;
1+ import React , { PropTypes } from 'react'
2+ import Frame from './frame'
33
4- const noop = ( ) => { } ;
4+ const noop = ( ) => { }
55
66export default class Keyframes extends React . Component {
77 static propTypes = {
88 children : PropTypes . arrayOf ( PropTypes . element ) . isRequired ,
9- component : PropTypes . any ,
9+ component : PropTypes . any , // eslint-disable-line react/no-unused-prop-types
1010 delay : PropTypes . number ,
1111 loop : PropTypes . oneOfType ( [
1212 React . PropTypes . string ,
@@ -25,92 +25,95 @@ export default class Keyframes extends React.Component {
2525 onEnd : noop
2626 } ;
2727
28- constructor ( props ) {
29- super ( props ) ;
28+ constructor ( props ) {
29+ super ( props )
3030 this . state = {
3131 frameNum : this . props . delay ? - 1 : 0 ,
3232 loopNum : 0
33- } ;
34- this . timer = null ;
33+ }
34+ this . timer = null
3535 }
3636
37- shouldComponentUpdate ( nextProps , nextState ) {
38- const { frameNum } = nextState ;
39- if ( this . state . frameNum === frameNum ) return false ;
40- return 0 <= frameNum && frameNum < this . props . children . length ;
37+ shouldComponentUpdate ( nextProps , nextState ) {
38+ const { frameNum} = nextState
39+ if ( this . state . frameNum === frameNum ) {
40+ return false
41+ }
42+ return frameNum >= 0 && frameNum < this . props . children . length
4143 }
4244
43- componentWillMount ( ) {
44- if ( 0 === this . state . frameNum ) {
45- this . props . onStart ( ) ;
45+ componentWillMount ( ) {
46+ if ( this . state . frameNum === 0 ) {
47+ this . props . onStart ( )
4648 }
4749 }
4850
49- componentWillUpdate ( ) {
50- if ( 0 === this . state . frameNum ) {
51- this . props . onStart ( ) ;
51+ componentWillUpdate ( ) {
52+ if ( this . state . frameNum === 0 ) {
53+ this . props . onStart ( )
5254 }
5355 }
5456
55- componentDidMount ( ) {
56- this . requestNextFrame ( ) ;
57+ componentDidMount ( ) {
58+ this . requestNextFrame ( )
5759 }
5860
59- componentDidUpdate ( ) {
60- this . requestNextFrame ( ) ;
61+ componentDidUpdate ( ) {
62+ this . requestNextFrame ( )
6163 }
6264
63- componentWillUnmount ( ) {
64- clearTimeout ( this . timer ) ;
65+ componentWillUnmount ( ) {
66+ clearTimeout ( this . timer )
6567 }
6668
67- render ( ) {
68- const frame = this . getFrame ( ) ;
69- if ( ! frame ) return null ;
69+ render ( ) {
70+ const frame = this . getFrame ( )
71+ if ( ! frame ) {
72+ return null
73+ }
7074
71- const props = { } ;
72- Object . keys ( this . props ) . forEach ( ( k ) => {
75+ const props = { }
76+ Object . keys ( this . props ) . forEach ( k => {
7377 // don't pass props which exist only on Keyframes
7478 if ( Keyframes . propTypes [ k ] && ! Frame . propTypes [ k ] ) {
75- return ;
79+ return
7680 }
7781
78- props [ k ] = this . props [ k ] ;
79- } ) ;
82+ props [ k ] = this . props [ k ]
83+ } )
8084
81- return React . cloneElement ( frame , { ...props , ...frame . props } ) ;
85+ return React . cloneElement ( frame , { ...props , ...frame . props } )
8286 }
8387
84- requestNextFrame ( ) {
88+ requestNextFrame ( ) {
8589 this . waitForDelay ( ( ) => {
86- const frameNum = this . state . frameNum + 1 ;
87- const loopNum = this . state . loopNum + 1 ;
90+ const frameNum = this . state . frameNum + 1
91+ const loopNum = this . state . loopNum + 1
8892 if ( this . props . children . length <= frameNum ) {
8993 if ( this . props . loop === true || this . props . loop === 'infinite' || loopNum < this . props . loop ) {
9094 this . setState ( {
9195 frameNum : 0 ,
9296 loopNum
93- } ) ;
94- this . requestNextFrame ( ) ;
95- return ;
96- } else {
97- this . props . onEnd ( ) ;
98- return ;
97+ } )
98+ this . requestNextFrame ( )
99+ return
99100 }
101+ this . props . onEnd ( )
102+ return
100103 }
101104
102- this . setState ( { frameNum } ) ;
103- } ) ;
105+ this . setState ( { frameNum} )
106+ } )
104107 }
105108
106- waitForDelay ( fn ) {
107- const currentFrame = this . getFrame ( ) ;
108- const delay = currentFrame ? currentFrame . props . duration : this . props . delay ;
109- clearTimeout ( this . timer ) ;
110- this . timer = setTimeout ( fn , delay ) ;
109+ waitForDelay ( fn ) {
110+ const currentFrame = this . getFrame ( )
111+ const delay = currentFrame ? currentFrame . props . duration : this . props . delay
112+ clearTimeout ( this . timer )
113+ this . timer = setTimeout ( fn , delay )
111114 }
112115
113- getFrame ( ) {
114- return this . props . children [ this . state . frameNum ] ;
116+ getFrame ( ) {
117+ return this . props . children [ this . state . frameNum ]
115118 }
116119}
0 commit comments