forked from Raynos/mercury
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared-state.js
More file actions
39 lines (33 loc) · 797 Bytes
/
shared-state.js
File metadata and controls
39 lines (33 loc) · 797 Bytes
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
'use strict';
var document = require('global/document');
var hg = require('../index.js');
var h = require('../index.js').h;
function App() {
return hg.state({
text: hg.value(''),
channels: {
change: setText
}
});
}
function setText(state, data) {
state.text.set(data.text);
}
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.channels.change)
])
]);
};
function inputBox(value, sink) {
return h('input.input', {
value: value,
name: 'text',
type: 'text',
'ev-event': hg.sendChange(sink)
});
}
hg.app(document.body, App(), App.render);