forked from reactive-python/reactpy-django
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.py
More file actions
112 lines (86 loc) · 2.73 KB
/
components.py
File metadata and controls
112 lines (86 loc) · 2.73 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from django.utils import timezone
from reactpy import component, hooks, html
@component
def renders_per_second():
start_time, _set_start_time = hooks.use_state(timezone.now())
count, set_count = hooks.use_state(0)
seconds_elapsed = (timezone.now() - start_time).total_seconds()
@hooks.use_effect
def run_tests():
set_count(count + 1)
rps = count / (seconds_elapsed or 0.01)
return html.div(
html.div(f"Total renders: {count}"),
html.div(
{"className": "rps", "data-rps": rps},
f"Renders Per Second: {rps}",
),
)
@component
def time_to_load():
return html.div({"className": "ttl"}, "Loaded!")
GIANT_STR_10MB = "@" * 10000000
@component
def net_io_time_to_load():
return html.div(
{"className": "ttl"},
html.div({"style": {"display": "none"}}, GIANT_STR_10MB),
html.div("Loaded!"),
)
GIANT_STR_1MB = "@" * 1000000
@component
def mixed_time_to_load():
start_time, _set_start_time = hooks.use_state(timezone.now())
count, set_count = hooks.use_state(0)
seconds_elapsed = (timezone.now() - start_time).total_seconds()
@hooks.use_effect
def run_tests():
set_count(count + 1)
rps = count / (seconds_elapsed or 0.01)
return html.div(
html.div({"style": {"display": "none"}}, GIANT_STR_1MB),
html.div(f"Total renders: {count}"),
html.div(
{"className": "rps", "data-rps": rps},
f"Renders Per Second: {rps}",
),
)
@component
def event_renders_per_second():
count, set_count = hooks.use_state(0)
start_time, _set_start_time = hooks.use_state(timezone.now())
seconds_elapsed = (timezone.now() - start_time).total_seconds()
erps = count / (seconds_elapsed or 0.01)
async def event_handler(event):
if event["target"]["value"] != str(count):
set_count(count + 1)
return html.div(
html.div(f"Total events: {count}"),
html.div(
{"className": "erps", "data-erps": erps},
f"Event Renders Per Second: {erps}",
),
html.input({
"type": "text",
"defaultValue": "0",
"data-count": str(count),
"onClick": event_handler,
}),
)
@component
def event_timing(worker_num: int):
clicked, set_clicked = hooks.use_state(False)
async def event_handler(_event):
set_clicked(True)
return html.div(
html.input(
{
"className": "et",
"data-clicked": clicked,
"data-worker-num": worker_num,
"value": f"Clicked: {clicked}",
"type": "button",
"onClick": event_handler,
},
),
)