- Added instructions to create the html.js file as requested per the issue. - Added the html.min.js file to the vanilla example - Tested and working as expected.
44 lines
1.2 KiB
HTML
44 lines
1.2 KiB
HTML
<html>
|
|
<head>
|
|
<title>Vanilla example</title>
|
|
</head>
|
|
<body>
|
|
<script src="../../dist/choo.min.js"></script>
|
|
<script src="../../dist/html.min.js"></script>
|
|
<script>
|
|
const app = choo()
|
|
|
|
app.model({
|
|
namespace: 'counter',
|
|
state: {
|
|
count: 0
|
|
},
|
|
reducers: {
|
|
increment: (data, state) => ({count: state.count + 1}),
|
|
decrement: (data, state) => ({count: state.count - 1})
|
|
}
|
|
})
|
|
|
|
const mainView = (state, prev, send) => {
|
|
return html`
|
|
<main class="app">
|
|
<h1>Counter example</h1>
|
|
<div>
|
|
Count: ${state.counter.count}
|
|
<button onclick=${(e) => send('counter:increment')}>+</button>
|
|
<button onclick=${(e) => send('counter:decrement')}>-</button>
|
|
</div>
|
|
</main>
|
|
`
|
|
}
|
|
|
|
app.router((route) => [
|
|
route('/', mainView)
|
|
])
|
|
|
|
const tree = app.start()
|
|
document.body.appendChild(tree)
|
|
</script>
|
|
</body>
|
|
</html>
|