Created
March 28, 2017 15:05
-
-
Save djyde/cb47277a70c485626eb134f67ce6fb82 to your computer and use it in GitHub Desktop.
Simplest cans counter application
This file contains hidden or 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
| import cans, { inject } from 'cans' | |
| import { observable, action } from 'cans/mobx' | |
| import { BrowserRouter, Route } from 'cans/router' | |
| const app = cans() | |
| // model | |
| app.model({ | |
| namespace: 'counter', | |
| observable: observable({ | |
| count: 0, | |
| incr: action.bound(function () { | |
| this.count += 1 | |
| }), | |
| decr: action.bound(function () { | |
| this.count -= 1 | |
| }) | |
| }) | |
| }) | |
| // view | |
| const Counter = inject(({ models })) => { | |
| return ( | |
| <div> | |
| <span>{models.counter.count}</span> | |
| <button onClick={models.counter.incr}>+</button> | |
| <button onClick={models.counter.decr}>-</button> | |
| </div> | |
| ) | |
| } | |
| // router | |
| const route = () => ( | |
| <BrowserRouter> | |
| <Route path='/' component={Counter} /> | |
| </BrowserRouter> | |
| ) | |
| app.route(route) | |
| // mount the app | |
| app.start(document.querySelector('#root')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment