-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
36 lines (24 loc) · 824 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
36
// main factory - no external dependencies
const createMount = ({
// configuration object
createStream, createElement, createTags, createRender
}) => ({
// component object
el, reducer, view, initState
// defaults
} = {
// defaults to no action if not provided
reducer: (state, actions) => state
}) => {
const actions = createStream()
const createElements = createTags(createElement)
const states = createStream.scan(reducer, initState, actions)
// pipe into view
// view events wil update the actionStream
const vnodes = states.map(state => view(createElements)(state, actions))
// render to DOM
vnodes.map(vnode => createRender(el)(vnode))
// return stream of vnodes, with states and actions streams patched
return Object.assign({}, vnodes, { states, actions })
}
module.exports = createMount