Skip to content

Commit 99c083e

Browse files
committed
Merge branch 'update-rts-1.4.3' of https://github.com/oleggrishechkin/js-framework-benchmark into oleggrishechkin-update-rts-1.4.3
2 parents 864be9f + f0015f9 commit 99c083e

File tree

3 files changed

+48
-47
lines changed

3 files changed

+48
-47
lines changed

frameworks/keyed/react-tagged-state/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/keyed/react-tagged-state/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
"dependencies": {
3434
"react": "17.0.1",
3535
"react-dom": "17.0.1",
36-
"react-tagged-state": "1.1.7"
36+
"react-tagged-state": "1.4.3"
3737
}
3838
}

frameworks/keyed/react-tagged-state/src/main.jsx

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {memo} from "react";
1+
import {memo, useCallback} from "react";
22
import {render} from "react-dom";
3-
import {batch, mutated, useTagged} from "react-tagged-state";
3+
import {createSignal, useSelector, useSignal} from "react-tagged-state";
44

55
const A = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean",
66
"elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive",
@@ -13,50 +13,50 @@ const random = (max) => Math.round(Math.random() * 1000) % max;
1313

1414
let nextId = 1;
1515

16-
const buildData = (res, count) => {
16+
const buildData = (count) => {
17+
const res = new Array(count);
18+
1719
for (let index = 0; index < count; index++) {
18-
res.push({
20+
res[index] = {
1921
id: nextId++,
2022
label: `${A[random(A.length)]} ${C[random(C.length)]} ${N[random(N.length)]}`
21-
})
23+
};
2224
}
25+
26+
return res;
2327
}
2428

25-
const data = [];
29+
const data = createSignal([]);
2630

27-
let selected = 0;
31+
let selected = createSignal(0);
2832

2933
const Row = memo(({item}) => {
30-
useTagged(item);
34+
const isSelected = useSelector(() => item.id === selected());
35+
const handleSelect = useCallback(() => {
36+
selected(item.id);
37+
}, [item.id]);
38+
const handleRemove = useCallback(() => {
39+
data((curr) => curr.filter(({id}) => id !== item.id));
40+
}, [item.id]);
3141

3242
return (
33-
<tr className={selected === item.id ? "danger" : ""}>
43+
<tr className={isSelected ? "danger" : ""}>
3444
<td className="col-md-1">{item.id}</td>
3545
<td className="col-md-4">
36-
<a onClick={() => batch(() => {
37-
if (selected) {
38-
mutated(data.find(({id}) => id === selected));
39-
}
40-
41-
selected = item.id;
42-
mutated(item);
43-
})}>{item.label}</a>
46+
<a onClick={handleSelect}>{item.label}</a>
4447
</td>
4548
<td className="col-md-1">
46-
<a onClick={() => {
47-
data.splice(data.indexOf(item), 1);
48-
mutated(data);
49-
}}><span className="glyphicon glyphicon-remove" aria-hidden="true"/></a>
49+
<a onClick={handleRemove}><span className="glyphicon glyphicon-remove" aria-hidden="true"/></a>
5050
</td>
5151
<td className="col-md-6"/>
5252
</tr>
5353
)
5454
});
5555

5656
const RowList = () => {
57-
useTagged(data);
57+
const items = useSignal(data);
5858

59-
return data.map((item) => <Row key={item.id} item={item}/>)
59+
return items.map((item) => <Row key={item.id} item={item}/>)
6060
};
6161

6262
const Button = ({id, title, cb}) => (
@@ -73,34 +73,35 @@ const Main = () => (
7373
<div className="col-md-6">
7474
<div className="row">
7575
<Button id="run" title="Create 1,000 rows" cb={() => {
76-
data.length = 0;
77-
selected = 0;
78-
buildData(data, 1000);
79-
mutated(data);
76+
data(buildData(1000));
77+
selected(0);
8078
}}/>
8179
<Button id="runlots" title="Create 10,000 rows" cb={() => {
82-
data.length = 0;
83-
selected = 0;
84-
buildData(data, 10000);
85-
mutated(data);
80+
data(buildData(10000));
81+
selected(0);
8682
}}/>
8783
<Button id="add" title="Append 1,000 rows" cb={() => {
88-
buildData(data, 1000);
89-
mutated(data);
84+
data((curr) => curr.concat(buildData(1000)));
85+
}}/>
86+
<Button id="update" title="Update every 10th row" cb={() => {
87+
data((curr) => {
88+
const copy = curr.slice(0);
89+
90+
for (let index = 0; index < copy.length; index += 10) {
91+
const item = copy[index];
92+
93+
copy[index] = {id: item.id, label: item.label + " !!!"};
94+
}
95+
96+
return copy;
97+
});
9098
}}/>
91-
<Button id="update" title="Update every 10th row" cb={() => batch(() => {
92-
for (let index = 0; index < data.length; index += 10) {
93-
mutated(data[index]).label += " !!!";
94-
}
95-
})}/>
9699
<Button id="clear" title="Clear" cb={() => {
97-
data.length = 0;
98-
selected = 0;
99-
mutated(data);
100+
data([]);
101+
selected(0);
100102
}}/>
101103
<Button id="swaprows" title="Swap Rows" cb={() => {
102-
[data[1], data[998]] = [data[998], data[1]];
103-
mutated(data);
104+
data((curr) => [curr[0], curr[998], ...curr.slice(2, 998), curr[1], curr[999]]);
104105
}}/>
105106
</div>
106107
</div>

0 commit comments

Comments
 (0)