added stopwatch example

added requestAnimationFrame polyfill

moved raf logic into a subscription

separated logic into multiple files, all state lives in a global namespaced model, reset no longer sends multiple actions only one
This commit is contained in:
traducer
2016-07-13 16:59:20 +00:00
parent a1795c29ee
commit 5f858cfdf5
5 changed files with 120 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
const html = require('../../../html')
const format = require('../utilities/format')
function toggle (state, send) {
if (state.start) {
send('stop')
} else {
send('start')
}
}
module.exports = (state, prev, send) => {
const start = state.start
const elapsed = state.elapsed
return html`
<main class="app">
<h1>stopwatch</h1>
<p>${format(elapsed)}</p>
<button
onclick=${e => toggle(state, send)}
>${start ? 'stop' : 'start'}</button>
<button
style="display:${start ? 'none' : 'inline'};"
onclick=${e => send('reset')}
>reset</button>
<button
style="display:${start ? 'inline' : 'none'};"
onclick=${e => send('add', format(elapsed))}
>lap</button>
<ol>
${state.laps.map(lap => html`<li>${lap}</li>`)}
</ol>
</main>
`
}