Skip to content

Commit 1bdd153

Browse files
committed
Fix swap bug fix
1 parent 6affa47 commit 1bdd153

File tree

1 file changed

+13
-25
lines changed
  • frameworks/keyed/rendrjs/src

1 file changed

+13
-25
lines changed

frameworks/keyed/rendrjs/src/App.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { rendr, useCallback, useState } from '@rendrjs/core';
22
import Jumbotron from './Jumbotron';
33
import Row from './Row';
44

5-
65
const random = (max) => Math.round(Math.random() * 1000) % max;
76

87
const A = ['pretty', 'large', 'big', 'small', 'tall', 'short', 'long', 'handsome',
@@ -49,39 +48,28 @@ const App = () => {
4948
return { data: newData, selected: old.selected };
5049
}), []);
5150
const onSwap = useCallback(() => setState(old => {
52-
if (old.data.length > 988) {
53-
return {
54-
data: [old.data[0], old.data[998], ...old.data.slice(2, 998), old.data[1], old.data[999]],
55-
selected: old.selected,
56-
};
51+
if (old.data.length > 998) {
52+
const d1 = old.data[1];
53+
const d998 = old.data[998];
54+
old.data[1] = d998;
55+
old.data[998] = d1;
56+
return { ...old };
5757
}
5858
return { data: old.data, selected: 0 };
5959
}), []);
6060
const onAppend = useCallback(() => setState(old => {
6161
return { data: old.data.concat(buildData(1000)), selected: old.selected };
6262
}), []);
63-
const onDelete = useCallback((id) => {
64-
setState(old => {
65-
const idx = old.data.findIndex((d) => d.id === id);
66-
return { data: [...old.data.slice(0, idx), ...old.data.slice(idx + 1)], selected: old.selected };
67-
});
68-
}, []);
69-
const onSelect = useCallback((id) => {
70-
setState(old => ({ ...old, selected: id }));
71-
}, []);
63+
const onDelete = useCallback((id) => setState(old => {
64+
old.data.splice(old.data.findIndex((d) => d.id === id), 1);
65+
return { ...old };
66+
}), []);
67+
const onSelect = useCallback((id) => setState(old => ({ ...old, selected: id })), []);
7268

7369
return rendr('div', {
7470
className: 'container',
7571
slot: [
76-
rendr(Jumbotron, {
77-
onRun,
78-
onRunlots,
79-
onClear,
80-
onUpdate,
81-
onSwap,
82-
onAppend,
83-
memo: [],
84-
}),
72+
rendr(Jumbotron, { onRun, onRunlots, onClear, onUpdate, onSwap, onAppend, memo: [] }),
8573
rendr('table', {
8674
className: 'table table-hover table-striped test-data',
8775
slot: rendr('tbody', {
@@ -91,7 +79,7 @@ const App = () => {
9179
selected: state.selected === item.id,
9280
onSelect,
9381
onDelete,
94-
memo: [item.label, item.id === state.selected],
82+
memo: [item.id === state.selected, item.label],
9583
})),
9684
}),
9785
}),

0 commit comments

Comments
 (0)