Files: e75defac47630de9da141ca0ca89cba54a030464 / test / dom.js
820 bytesRaw
1 | var Struct = require('../struct') |
2 | var send = require('../send') |
3 | var h = require('../html-element') |
4 | |
5 | var state = Struct({ |
6 | text: 'Test', |
7 | color: 'red', |
8 | value: 0 |
9 | }) |
10 | |
11 | var element = h('div.cool', { |
12 | classList: ['cool', state.text], |
13 | style: { |
14 | 'background-color': state.color |
15 | } |
16 | }, [ |
17 | h('div', [ |
18 | state.text, ' ', state.value, ' ', h('strong', 'test') |
19 | ]), |
20 | h('div', [ |
21 | h('button', { |
22 | 'ev-click': send(state.color.set, 'blue') |
23 | }, 'Change color') |
24 | ]) |
25 | ]) |
26 | |
27 | setTimeout(function () { |
28 | state.text.set('Another value') |
29 | }, 5000) |
30 | |
31 | setInterval(function () { |
32 | state.value.set(state.value() + 1) |
33 | }, 1000) |
34 | |
35 | setInterval(function () { |
36 | // bulk update state |
37 | state.set({ |
38 | text: 'Retrieved from server (not really)', |
39 | color: '#FFEECC', |
40 | value: 1337 |
41 | }) |
42 | }, 10000) |
43 | |
44 | document.body.appendChild(element) |
45 |
Built with git-ssb-web