Skip to content

Commit 699dc00

Browse files
authored
Update main.jsx
1 parent 1ee1707 commit 699dc00

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

frameworks/keyed/fre/src/main.jsx

Lines changed: 11 additions & 11 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 "../node_modules/fre/dist/fre.esm.js"
22

33
function random(max) {
44
return Math.round(Math.random() * 1000) % max
@@ -78,7 +78,7 @@ function listReducer(state, action) {
7878
const { data, selected } = state
7979
switch (action.type) {
8080
case "RUN":
81-
return { data: buildData(1000), selected: 0 }
81+
return { data: buildData(10), selected: 0 }
8282
case "RUN_LOTS":
8383
return { data: buildData(10000), selected: 0 }
8484
case "ADD":
@@ -93,14 +93,14 @@ function listReducer(state, action) {
9393
case "CLEAR":
9494
return { data: [], selected: 0 }
9595
case "SWAP_ROWS":
96-
return data.length > 998
96+
return data.length > 8
9797
? {
9898
data: [
9999
data[0],
100-
data[998],
101-
...data.slice(2, 998),
100+
data[8],
101+
...data.slice(2, 8),
102102
data[1],
103-
data[999],
103+
data[9],
104104
],
105105
}
106106
: state
@@ -113,7 +113,7 @@ function listReducer(state, action) {
113113
return state
114114
}
115115

116-
const Row = ({ selected, item, dispatch }) => {
116+
const Row = memo(({ selected, item, dispatch, id }) => {
117117
return (
118118
<tr className={selected ? "danger" : ""}>
119119
<td className="col-md-1">{item.id}</td>
@@ -129,7 +129,7 @@ const Row = ({ selected, item, dispatch }) => {
129129
<td className="col-md-6" />
130130
</tr>
131131
)
132-
}
132+
})
133133

134134
const Button = ({ id, cb, title }) => (
135135
<div className="col-sm-6 smallpad">
@@ -145,7 +145,7 @@ const Button = ({ id, cb, title }) => (
145145
)
146146

147147

148-
const Jumbotron = ({ dispatch }) => (
148+
const Jumbotron = memo(({ dispatch }) => (
149149
<div className="jumbotron">
150150
<div className="row">
151151
<div className="col-md-6">
@@ -187,7 +187,7 @@ const Jumbotron = ({ dispatch }) => (
187187
</div>
188188
</div>
189189
</div>
190-
)
190+
))
191191

192192
const Main = () => {
193193
const [state, setState] = useReducer(listReducer, { data: [], selected: 0 })
@@ -215,4 +215,4 @@ const Main = () => {
215215
)
216216
}
217217

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

0 commit comments

Comments
 (0)