Skip to content

Commit dfea67e

Browse files
committed
Merge branch 'patch-1' of https://github.com/yisar/js-framework-benchmark into yisar-patch-1
2 parents 9cec4f9 + a95f9ba commit dfea67e

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

frameworks/keyed/fre/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-framework-benchmark-fre",
3-
"version": "2.2.1",
3+
"version": "2.5.5",
44
"description": "fre demo",
55
"main": "index.js",
66
"js-framework-benchmark": {
@@ -31,6 +31,6 @@
3131
"webpack-cli": "4.8.0"
3232
},
3333
"dependencies": {
34-
"fre": "2.4.3"
34+
"fre": "2.5.5"
3535
}
3636
}

frameworks/keyed/fre/src/main.jsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, render, useReducer, useCallback } from "fre"
1+
import { h, render, useReducer, useCallback, memo } from "fre"
22

33
function random(max) {
44
return Math.round(Math.random() * 1000) % max
@@ -93,17 +93,7 @@ function listReducer(state, action) {
9393
case "CLEAR":
9494
return { data: [], selected: 0 }
9595
case "SWAP_ROWS":
96-
return data.length > 998
97-
? {
98-
data: [
99-
data[0],
100-
data[998],
101-
...data.slice(2, 998),
102-
data[1],
103-
data[999],
104-
],
105-
}
106-
: state
96+
return data.length > 998 ? { data: [data[0], data[998], ...data.slice(2, 998), data[1], data[999]], selected } : state
10797
case "REMOVE":
10898
const idx = data.findIndex((d) => d.id === action.id)
10999
return { data: [...data.slice(0, idx), ...data.slice(idx + 1)], selected }
@@ -113,7 +103,7 @@ function listReducer(state, action) {
113103
return state
114104
}
115105

116-
const Row = ({ selected, item, dispatch }) => {
106+
const Row = memo(({ selected, item, dispatch, id }) => {
117107
return (
118108
<tr className={selected ? "danger" : ""}>
119109
<td className="col-md-1">{item.id}</td>
@@ -129,7 +119,7 @@ const Row = ({ selected, item, dispatch }) => {
129119
<td className="col-md-6" />
130120
</tr>
131121
)
132-
}
122+
})
133123

134124
const Button = ({ id, cb, title }) => (
135125
<div className="col-sm-6 smallpad">
@@ -145,7 +135,7 @@ const Button = ({ id, cb, title }) => (
145135
)
146136

147137

148-
const Jumbotron = ({ dispatch }) => (
138+
const Jumbotron = memo(({ dispatch }) => (
149139
<div className="jumbotron">
150140
<div className="row">
151141
<div className="col-md-6">
@@ -187,7 +177,7 @@ const Jumbotron = ({ dispatch }) => (
187177
</div>
188178
</div>
189179
</div>
190-
)
180+
))
191181

192182
const Main = () => {
193183
const [state, setState] = useReducer(listReducer, { data: [], selected: 0 })
@@ -215,4 +205,4 @@ const Main = () => {
215205
)
216206
}
217207

218-
render(<Main />, document.getElementById("main"), { sync: true })
208+
render(<Main />, document.getElementById("main"))

0 commit comments

Comments
 (0)