Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brigand

brigand/.jsx Secret

Created August 15, 2017 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brigand/5df7d7bb5f245ece4ab08d6e4aa85050 to your computer and use it in GitHub Desktop.
Save brigand/5df7d7bb5f245ece4ab08d6e4aa85050 to your computer and use it in GitHub Desktop.
class Hello extends vidom.Component {
onInit() {
this.setState({ counter : 1 });
}
onRender() {
return (
<div>
<div>Root counter {this.state.counter}</div>
{this.state.counter % 2 === 0 ? <Counter1 /> : <Counter2 />}
{this.state.counter % 2 === 1 ? <Counter1 /> : <Counter2 />}
</div>
);
}
onMount() {
setInterval(() => {
this.setState({ counter : this.state.counter + 1 });
}, 1000);
}
}
class Counter1 extends vidom.Component {
onInit() {
this.setState({ counter : 1 });
}
onRender() {
return (
<div>
<div>Counter1 { this.state.counter }</div>
</div>
);
}
onMount() {
setInterval(() => {
this.setState({ counter : this.state.counter + 1 });
}, 1000);
}
}
class Counter2 extends vidom.Component {
onInit() {
this.setState({ counter : 1 });
}
onRender() {
return (
<div>
<div>Counter2 { this.state.counter }</div>
</div>
);
}
onMount() {
setInterval(() => {
this.setState({ counter : this.state.counter + 1 });
}, 1000);
}
}
vidom.mount(document.body, <Hello name="World"/>);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment