-
-
Save rbiggs/cc6535d1edc7954e24c75b5e22c47ac1 to your computer and use it in GitHub Desktop.
@composi/core runtime program -- Counter
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
| // Counter for view: | |
| function Counter({state, send}) { | |
| return ( | |
| <p> | |
| <button onclick={() => history.go(0)} id='reload-btn'>Restart</button> | |
| <button class='counter' onclick={() => send()}>{state}</button> | |
| </p> | |
| ) | |
| } | |
| // Assemble program together: | |
| const program = { | |
| init() { | |
| return [0] | |
| }, | |
| view(state, send) { | |
| render(<Counter {...{state, send}} />, document.body) | |
| }, | |
| update(msg, state) { | |
| return [state + 1] | |
| } | |
| } | |
| // Run the program: | |
| run(program) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment