-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathOptimizedEvents.njs
More file actions
73 lines (63 loc) · 1.68 KB
/
OptimizedEvents.njs
File metadata and controls
73 lines (63 loc) · 1.68 KB
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
68
69
70
71
72
73
import Nullstack from 'nullstack'
class OptimizedEvents extends Nullstack {
count = 0
clickWhenEven() {
this.lastClick = 'even'
}
clickWhenOdd() {
this.lastClick = 'odd'
}
incrementCount() {
this.count++
}
doubleCount({ data }) {
this.count += data.count
}
eventAfterRendered() {
this.worksAfterRender = true
}
render() {
return (
<main data-hydrated={this.hydrated}>
{this.count === 1 && (
<div>
<button
onclick={this.eventAfterRendered}
data-works-after-rendered={this.worksAfterRender}
data-after-render
>
after render
</button>
</div>
)}
<button onclick={() => (this.count = 10 + this.count)} data-set-count>
add 10
</button>
<button
onclick={this.count % 2 === 0 ? this.clickWhenEven : this.clickWhenOdd}
data-last-click={this.lastClick}
data-even-odd
>
even odd
</button>
<button onclick={this.count === 0 ? this.incrementCount : undefined} data-zero-only-increment>
zero only
</button>
{this.count === 0 ? (
<button onclick={this.incrementCount} data-zero-nothing-increment>
zero only
</button>
) : (
<button data-zero-nothing-increment> nothing </button>
)}
<button onclick={this.incrementCount} data-increment-count>
increment
</button>
<button onclick={this.doubleCount} data-count={this.count} data-double-count>
double
</button>
</main>
)
}
}
export default OptimizedEvents