forked from YerkoPalma/choo-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
34 lines (30 loc) · 829 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const html = require('choo/html')
const offline = require('./')
const choo = require('choo')
const app = choo()
app.model({
state: {
count: 0
},
reducers: {
increment: (action, state) => ({ count: state.count + 1 }),
/**
* If you turn off your internet connection, then the button of the example
* app will decrement instead of increment the count,
* keep in mind that the increment reducer get called too.
*/
decrement: (action, state) => ({ count: state.count - 2 })
}
})
app.router(route => [
route('/', (state, prev, send) => html`
<main>
<h1>${state.count}</h1>
<button onclick=${() => send('increment', { _backup: 'decrement' })}>+1</button>
</main>
`)])
offline((offline) => {
app.use(offline)
const tree = app.start()
document.body.appendChild(tree)
})