Skip to content

Commit f411bda

Browse files
committed
qwik: use components to speed up actions
1 parent 0404bfa commit f411bda

File tree

1 file changed

+50
-27
lines changed
  • frameworks/keyed/qwik/src/components/app

1 file changed

+50
-27
lines changed

frameworks/keyed/qwik/src/components/app/index.tsx

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,48 @@ export function buildData(count: number) {
7474
return data;
7575
}
7676

77+
export const Row = component$(
78+
({
79+
item,
80+
state,
81+
isSelected,
82+
}: {
83+
item: BenchState["data"][0];
84+
state: BenchState;
85+
isSelected: boolean;
86+
}) => {
87+
const { id, label } = item;
88+
return (
89+
<tr class={isSelected ? "danger" : ""}>
90+
<td class="col-md-1">{item.id}</td>
91+
<td class="col-md-4">
92+
<a
93+
onClick$={() => {
94+
state.selected = id;
95+
}}
96+
>
97+
{label}
98+
</a>
99+
</td>
100+
<td class="col-md-1">
101+
<a
102+
onClick$={() => {
103+
const d = state.data;
104+
d.splice(
105+
d.findIndex((d) => d.id === id),
106+
1
107+
);
108+
}}
109+
>
110+
<span class="glyphicon glyphicon-remove" aria-hidden="true" />
111+
</a>
112+
</td>
113+
<td class="col-md-6" />
114+
</tr>
115+
);
116+
}
117+
);
118+
77119
type BenchState = {
78120
data: Array<{ id: number; label: string }>;
79121
selected: number | null;
@@ -163,33 +205,14 @@ export const App = component$(() => {
163205
</div>
164206
<table class="table table-hover table-striped test-data">
165207
<tbody>
166-
{state.data.map(({ id, label }) => {
167-
return (
168-
<tr key={id} class={id === state.selected ? "danger" : ""}>
169-
<td class="col-md-1">{id}</td>
170-
<td class="col-md-4">
171-
<a onClick$={() => (state.selected = id)}>{label}</a>
172-
</td>
173-
<td class="col-md-1">
174-
<a
175-
onClick$={() => {
176-
const d = state.data;
177-
d.splice(
178-
d.findIndex((d) => d.id === id),
179-
1
180-
);
181-
}}
182-
>
183-
<span
184-
class="glyphicon glyphicon-remove"
185-
aria-hidden="true"
186-
/>
187-
</a>
188-
</td>
189-
<td class="col-md-6" />
190-
</tr>
191-
);
192-
})}
208+
{state.data.map((item) => (
209+
<Row
210+
key={item.id}
211+
item={item}
212+
state={state}
213+
isSelected={item.id === state.selected}
214+
/>
215+
))}
193216
</tbody>
194217
</table>
195218
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true" />

0 commit comments

Comments
 (0)