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
62
63
64
65
66
67
|
let state = {};
let internalState = {};
const KEY_ENTER = 13;
state.currentChar = '你';
function setState(key, value)
{
state[key] = value;
render();
}
const CurrentCharacter = function({character})
{
return h(
'h1',
{ onClick: () => setState('currentChar', '我') },
character
);
}
function shakeInputBox()
{
setState('inputShaking', true);
setTimeout(() => setState('inputShaking', false), 300);
}
const App = function()
{
const { currentChar, inputValue, inputShaking } = state;
return h(
'div', {},
[
h(CurrentCharacter,
{ character: currentChar
}),
h(InputBox,
{ value: inputValue,
shouldGrabFocus: true,
shaking: inputShaking,
handleKeyDown: (e) =>
{
if (e.keyCode == KEY_ENTER) {
console.log(inputValue);
}
else {
setTimeout(() => setState('inputValue', e.target.value), 0);
}
}
}),
h(StyleButton,
{
text: 'hello, world',
enabled: true,
handleClick: () => {
console.log('hi there');
},
}),
]
);
}
|