Skip to content

Commit 3b17881

Browse files
committed
move store updates outside of functional component
1 parent 701f3a3 commit 3b17881

File tree

1 file changed

+31
-30
lines changed
  • frameworks/keyed/preact-signals/src

1 file changed

+31
-30
lines changed

frameworks/keyed/preact-signals/src/main.jsx

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -93,37 +93,38 @@ const Button = ({ id, text, fn }) => (
9393
const data = signal([]);
9494
const selected = signal(null);
9595

96-
const App = () => {
97-
const run = () => {
98-
data.value = buildData(1000);
99-
},
100-
runLots = () => (data.value = buildData(10000)),
101-
add = () => {
102-
data.value = data.value.concat(buildData(1000));
103-
},
104-
update = () =>
105-
batch(() => {
106-
for (let i = 0, d = data.value, len = d.length; i < len; i += 10) {
107-
d[i].label.value = d[i].label.value + " !!!";
108-
}
109-
}),
110-
swapRows = () => {
111-
const d = data.value.slice();
112-
if (d.length > 998) {
113-
let tmp = d[1];
114-
d[1] = d[998];
115-
d[998] = tmp;
116-
data.value = d;
96+
const run = () => {
97+
data.value = buildData(1000);
98+
},
99+
runLots = () => (data.value = buildData(10000)),
100+
add = () => {
101+
data.value = data.value.concat(buildData(1000));
102+
},
103+
update = () =>
104+
batch(() => {
105+
for (let i = 0, d = data.value, len = d.length; i < len; i += 10) {
106+
d[i].label.value = d[i].label.value + " !!!";
117107
}
118-
},
119-
clear = () => (data.value = []),
120-
remove = (id) => {
121-
const idx = data.value.findIndex((d) => d.id === id);
122-
data.value = [...data.value.slice(0, idx), ...data.value.slice(idx + 1)];
123-
},
124-
select = (id) => {
125-
selected.value = id;
126-
};
108+
}),
109+
swapRows = () => {
110+
const d = data.value.slice();
111+
if (d.length > 998) {
112+
let tmp = d[1];
113+
d[1] = d[998];
114+
d[998] = tmp;
115+
data.value = d;
116+
}
117+
},
118+
clear = () => (data.value = []),
119+
remove = (id) => {
120+
const idx = data.value.findIndex((d) => d.id === id);
121+
data.value = [...data.value.slice(0, idx), ...data.value.slice(idx + 1)];
122+
},
123+
select = (id) => {
124+
selected.value = id;
125+
};
126+
127+
const App = () => {
127128

128129
return (
129130
<div class="container">

0 commit comments

Comments
 (0)