-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (51 loc) · 1.31 KB
/
index.js
File metadata and controls
61 lines (51 loc) · 1.31 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import xs from 'xstream';
import {createElement} from 'react';
import {render} from 'react-dom';
import {h, makeComponent, useModules} from '../src/index';
function main(sources) {
const init$ = xs.of(() => 0);
const increment$ = xs.periodic(1000).mapTo(x => x + 1);
const btnSel = Symbol();
const reset$ = sources.react
.select(btnSel)
.events('click')
.mapTo(() => 0);
const count$ = xs
.merge(init$, increment$, reset$)
.fold((state, fn) => fn(state));
const getRef = el => {
el.foo='bar';
}
const vdom$ = count$.map(i => {
return h('div', [
h('h1', {ref: getRef}, `Hello ${i} times`),
h('button', {
sel: btnSel,
className: 'clicker',
domProps: {foo: 3},
domClass: {hello: true, goodbye: false}
}, 'Reset')
])
});
return {
react: vdom$,
};
}
const App = makeComponent(main);
useModules({
domProps: {
componentDidUpdate: (element, props) => {
Object.entries(props).forEach(([key, val]) => {
element[key] = val;
});
}
},
domClass: {
componentDidUpdate: (element, props) => {
Object.entries(props).forEach(([key, val]) => {
val ? element.classList.add(key) : element.classList.remove(key);
});
}
}
})
render(createElement(App), document.getElementById('app'));