Created
October 12, 2016 07:19
-
-
Save emanchado/9514b4219841fbfd03c1fed90b8ce99b to your computer and use it in GitHub Desktop.
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
const choo = require('choo') | |
const html = require('choo/html') | |
const app = choo() | |
app.model({ | |
state: { selected: 'second' }, | |
reducers: { | |
update: (data, state) => ({ selected: data }) | |
} | |
}) | |
const mainView = (state, prev, send) => html` | |
<main> | |
<h1>Title: ${state.selected}</h1> | |
<select onchange=${(e) => send('update', e.target.value)}> | |
<option value="first" ${ state.selected === 'first' ? 'selected' : '' }>First</option> | |
<option value="second" ${ state.selected === 'second' ? 'selected' : '' }>Second</option> | |
<option value="third" ${ state.selected === 'third' ? 'selected' : '' }>Third</option> | |
</select> | |
<button onclick=${(e) => send('update', 'third')}>reset</button> | |
</main> | |
` | |
app.router((route) => [ | |
route('/', mainView) | |
]) | |
const tree = app.start() | |
document.body.appendChild(tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment