Skip to content

Instantly share code, notes, and snippets.

@vdsabev
Last active August 17, 2017 09:17
Show Gist options
  • Save vdsabev/e1df1a9a8b900b1ac92860bd3d2594b2 to your computer and use it in GitHub Desktop.
Save vdsabev/e1df1a9a8b900b1ac92860bd3d2594b2 to your computer and use it in GitHub Desktop.
Exploring Unidirectional Components in Mithril
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