-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 912 Bytes
/
index.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
import {hashRouter} from "https://cdn.jsdelivr.net/gh/marcodpt/[email protected]/index.js"
import * as components from './src/components.js'
import active from './src/plugins/active/index.js'
export default ({root, build, routes, plugins}) => {
root = root || document.body
build = typeof build == 'function' ? build : (() => ({}))
routes = routes || {}
plugins = [active].concat(plugins || [])
var stop = null
Promise.resolve()
.then(() => typeof build === 'function' ? build(components) : null)
.then(addons => {
if (stop == null) {
stop = hashRouter({
init: () => ({
...(addons || {}),
...components,
root,
render: (view, el) => components.render(view, el || root)
}),
routes,
plugins
})
}
})
return () => {
if (typeof stop == 'function') {
stop()
}
}
}