-
-
Save brigand/5df7d7bb5f245ece4ab08d6e4aa85050 to your computer and use it in GitHub Desktop.
This file contains 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
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