forked from Raynos/mercury
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared-state.js
41 lines (34 loc) · 857 Bytes
/
shared-state.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
41
var document = require('global/document');
var hg = require('../index.js');
var h = require('../index.js').h;
function App() {
var state = hg.struct({
text: hg.value(''),
handles: hg.value(null)
});
state.handles.set(hg.handles({
change: setText
}, state));
return state;
}
function inputBox(value, sink) {
return h('input.input', {
value: value,
name: 'text',
type: 'text',
'ev-event': hg.changeEvent(sink)
});
}
App.render = function render(state) {
return h('div', [
h('p.content', 'The value is now: ' + state.text),
h('p', [
'Change it here: ',
inputBox(state.text, state.handles.change)
])
]);
};
function setText(state, data) {
state.text.set(data.text);
}
hg.app(document.body, App(), App.render);