forked from paldepind/functional-frontend-architecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
40 lines (33 loc) · 1.02 KB
/
main.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
35
36
37
38
39
40
const R = require('ramda')
const Type = require('union-type')
const patch = require('snabbdom').init([
require('snabbdom/modules/class'),
require('snabbdom/modules/props'),
require('snabbdom/modules/eventlisteners'),
require('snabbdom/modules/style'),
]);
const h = require('snabbdom/h')
require('./style.css')
let component = require('./counters.js')
let state = component.init()
let vnode
const render = () => vnode = patch(vnode, component.view(update, state))
// If hot module replacement is enabled
if (module.hot) {
// We accept updates to the top component
module.hot.accept('./counters.js', (comp) => {
// Mutate the variable holding our component
component = require('./counters.js')
// Render view in the case that any view functions has changed
render()
})
}
const update = (action) => {
state = component.update(action, state)
render()
}
// Begin rendering when the DOM is ready
window.addEventListener('DOMContentLoaded', () => {
vnode = document.getElementById('container')
render()
})