Last active
August 29, 2015 14:27
-
-
Save yang/abfa029b7e173b02191c to your computer and use it in GitHub Desktop.
Testing out React diff algo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TimerA = React.createClass({ | |
getInitialState: function() { | |
return {start: this.props.start}; | |
}, | |
render: function() { | |
return ( | |
<div>Seconds Elapsed: {this.state.start}</div> | |
); | |
} | |
}); | |
var TimerB = React.createClass({ | |
getInitialState: function() { | |
return {start: this.props.start}; | |
}, | |
render: function() { | |
return ( | |
<div>Seconds Elapsed: {this.state.start}</div> | |
); | |
} | |
}); | |
var Timer1 = React.createClass({ | |
getInitialState: function() { | |
return {config: 0}; | |
}, | |
tick: function() { this.setState({config:1}); }, | |
componentDidMount: function() { | |
setTimeout(this.tick, 1000); | |
}, | |
render: function() { | |
return ( | |
<div> | |
config={this.state.config} | |
<div> | |
{this.state.config == 1 ? <TimerA start='' /> : <div />}; | |
<TimerB start={this.state.config} />; | |
</div> | |
{ | |
this.state.config == 0 ? | |
<div>{[ | |
<TimerA key='a' start='0' />, | |
null, | |
<TimerB start='1' /> | |
]}</div> | |
: | |
<div>{[ | |
<TimerB key='a' start='11' />, | |
<TimerB start='10' />, | |
<TimerB start='11' />, | |
<TimerB start='12' /> | |
]}</div> | |
} | |
</div> | |
); | |
} | |
}); | |
React.render(<Timer1 />, mountNode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment