Last active
August 17, 2017 09:17
-
-
Save vdsabev/e1df1a9a8b900b1ac92860bd3d2594b2 to your computer and use it in GitHub Desktop.
Exploring Unidirectional Components in Mithril
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 Counter { | |
oninit({ attrs }) { | |
this.count = attrs.count || 0; | |
} | |
decrement = () => this.count--; | |
increment = () => this.count++; | |
view() { | |
return ( | |
<div> | |
<h1>{this.count}</h1> | |
<button onclick={this.decrement} disabled={this.count <= 0}>-</button> | |
<button onclick={this.increment}>+</button> | |
</div> | |
); | |
} | |
} | |
m.mount(document.body, { | |
view: () => <Counter /> | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment