Skip to content

Commit 3cc6591

Browse files
committed
fix(block): update benchmark
1 parent 37e11c4 commit 3cc6591

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

frameworks/keyed/million/src/main.jsx

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import {
22
createBlock,
3-
createFragment,
4-
// make sure you import your local version of million
5-
} from '/Users/aidenybai/Projects/aidenybai/million/packages/next/index';
3+
fragment,
4+
} from '/Users/aidenybai/Projects/aidenybai/million/packages/block/index';
65

76
const adjectives = [
87
'pretty',
@@ -86,24 +85,28 @@ const buildData = (count) => {
8685
return data;
8786
};
8887

89-
const create1k = () => {
88+
const create1k = (event) => {
89+
event.stopPropagation();
9090
if (list.length) clear();
9191
list = buildData(1000);
9292
update();
9393
};
9494

95-
const create10k = () => {
95+
const create10k = (event) => {
96+
event.stopPropagation();
9697
if (list.length) clear();
9798
list = buildData(10000);
9899
update();
99100
};
100101

101-
const append1k = () => {
102+
const append1k = (event) => {
103+
event.stopPropagation();
102104
list = list.concat(buildData(1000));
103105
update();
104106
};
105107

106-
const updateEvery10 = () => {
108+
const updateEvery10 = (event) => {
109+
event.stopPropagation();
107110
let i = 0;
108111
while (i < list.length) {
109112
list[i].label = `${list[i].label} !!!`;
@@ -112,7 +115,8 @@ const updateEvery10 = () => {
112115
update();
113116
};
114117

115-
const swapRows = () => {
118+
const swapRows = (event) => {
119+
event.stopPropagation();
116120
if (list.length > 998) {
117121
const item = list[1];
118122
list[1] = list[998];
@@ -134,6 +138,13 @@ const remove = (id) => {
134138
update();
135139
};
136140

141+
const shouldUpdate = (oldProps, newProps) => {
142+
return (
143+
oldProps.label !== newProps.label ||
144+
oldProps.className !== newProps.className
145+
);
146+
};
147+
137148
const Main = createBlock(({ rows }) => (
138149
<div class="container">
139150
<div class="jumbotron">
@@ -188,7 +199,8 @@ const Main = createBlock(({ rows }) => (
188199
type="button"
189200
class="btn btn-primary btn-block"
190201
id="clear"
191-
onClick={() => {
202+
onClick={(event) => {
203+
event.stopPropagation();
192204
clear();
193205
update();
194206
}}
@@ -238,7 +250,7 @@ const Row = createBlock(({ className, id, select, remove, label }) => {
238250
});
239251

240252
function Rows({ oldCache, newCache }) {
241-
return createFragment(
253+
return fragment(
242254
list.map((item) => {
243255
const isSelected = selected === item.id;
244256
const cachedItem = oldCache[item.id];
@@ -253,12 +265,19 @@ function Rows({ oldCache, newCache }) {
253265
id={item.id}
254266
label={item.label}
255267
className={isSelected ? 'danger' : ''}
256-
remove={() => remove(item.id)}
257-
select={() => select(item.id)}
268+
remove={(event) => {
269+
event.stopPropagation();
270+
remove(item.id);
271+
}}
272+
select={(event) => {
273+
event.stopPropagation();
274+
select(item.id);
275+
}}
258276
/>
259277
);
260278
row._data = [item.label, isSelected];
261279
row.key = String(item.id);
280+
row.shouldUpdate = shouldUpdate;
262281
newCache[item.id] = row;
263282
return row;
264283
})

0 commit comments

Comments
 (0)