-
Notifications
You must be signed in to change notification settings - Fork 56
/
jsx-control-statements-example.jsx
50 lines (46 loc) · 1.11 KB
/
jsx-control-statements-example.jsx
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
const skate = require('skatejs')
const {
url_to_domain,
} = require('libs_common/domain_utils')
const {
get_seconds_spent_on_domain_today,
} = require('libs_common/time_spent_utils')
const update_page = (elem) => {
get_seconds_spent_on_domain_today(elem.site, (seconds_spent) => {
elem.seconds = seconds_spent
})
}
skate.define('jsx-control-statements-example', {
props: {
site: { default: url_to_domain(window.location.href) },
seconds: { default: 0 },
example_array: { default: ['foo', 'bar', 'baz', 'qux']},
},
render: (elem) => {
const elem_style = {
'background-color': 'green',
'position': 'fixed',
'color': 'white',
'width': '100px',
'top': '0px',
'right': '0px',
'z-index': 99999,
}
return (
<div style={elem_style}>
Spent {elem.seconds} seconds on {elem.site}<br/>
{
<For each="obj" index="idx" of={elem.example_array}>
<div>{obj} is at index {idx}</div>
</For>
}
</div>
)
},
attached: (elem) => {
update_page(elem)
setInterval(() => {
update_page(elem)
}, 1000)
},
})