Skip to content

Instantly share code, notes, and snippets.

@yang
Last active August 29, 2015 14:27
Show Gist options
  • Save yang/abfa029b7e173b02191c to your computer and use it in GitHub Desktop.
Save yang/abfa029b7e173b02191c to your computer and use it in GitHub Desktop.
Testing out React diff algo
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