Skip to content

Commit 37e11c4

Browse files
committed
update
1 parent 6c3f6ed commit 37e11c4

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

frameworks/keyed/million/src/main.jsx

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
createBlock,
3-
$wire,
4-
fragment,
5-
} from '/Users/aidenybai/Projects/aidenybai/million/packages/next/block';
3+
createFragment,
4+
// make sure you import your local version of million
5+
} from '/Users/aidenybai/Projects/aidenybai/million/packages/next/index';
66

77
const adjectives = [
88
'pretty',
@@ -64,11 +64,13 @@ const random = (max) => Math.round(Math.random() * 1000) % max;
6464

6565
let nextId = 1;
6666
let list = [];
67+
let main;
6768
let selected = 0;
6869

6970
const clear = () => {
7071
list = [];
71-
update();
72+
main.children = [];
73+
main.remove();
7274
};
7375

7476
const buildData = (count) => {
@@ -85,19 +87,19 @@ const buildData = (count) => {
8587
};
8688

8789
const create1k = () => {
88-
clear();
90+
if (list.length) clear();
8991
list = buildData(1000);
9092
update();
9193
};
9294

9395
const create10k = () => {
94-
clear();
96+
if (list.length) clear();
9597
list = buildData(10000);
9698
update();
9799
};
98100

99101
const append1k = () => {
100-
list.concat(buildData(1000));
102+
list = list.concat(buildData(1000));
101103
update();
102104
};
103105

@@ -218,29 +220,15 @@ const Main = createBlock(({ rows }) => (
218220
</div>
219221
));
220222

221-
const Row = createBlock(({ className, id, label }) => {
223+
const Row = createBlock(({ className, id, select, remove, label }) => {
222224
return (
223225
<tr class={className}>
224226
<td class="col-md-1">{id}</td>
225227
<td class="col-md-4">
226-
<a
227-
onClick={$wire(({ id }) => {
228-
return () => {
229-
select(id);
230-
};
231-
}, id)}
232-
>
233-
{label}
234-
</a>
228+
<a onClick={select}>{label}</a>
235229
</td>
236230
<td class="col-md-1">
237-
<a
238-
onClick={$wire(({ id }) => {
239-
return () => {
240-
remove(id);
241-
};
242-
}, id)}
243-
>
231+
<a onClick={remove}>
244232
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
245233
</a>
246234
</td>
@@ -250,7 +238,7 @@ const Row = createBlock(({ className, id, label }) => {
250238
});
251239

252240
function Rows({ oldCache, newCache }) {
253-
return fragment(
241+
return createFragment(
254242
list.map((item) => {
255243
const isSelected = selected === item.id;
256244
const cachedItem = oldCache[item.id];
@@ -265,11 +253,13 @@ function Rows({ oldCache, newCache }) {
265253
id={item.id}
266254
label={item.label}
267255
className={isSelected ? 'danger' : ''}
256+
remove={() => remove(item.id)}
257+
select={() => select(item.id)}
268258
/>
269259
);
270260
row._data = [item.label, isSelected];
271261
row.key = String(item.id);
272-
newCache[row.id] = row;
262+
newCache[item.id] = row;
273263
return row;
274264
})
275265
);
@@ -281,7 +271,7 @@ function render(oldCache, newCache) {
281271

282272
let oldCache = {};
283273

284-
const main = render({}, oldCache);
274+
main = render({}, oldCache);
285275
(<Main rows={main} />).mount(document.getElementById('main'));
286276

287277
function update() {

frameworks/keyed/million/vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { million } from 'million/vite-plugin-million';
33

44
// https://vitejs.dev/config/
55
export default defineConfig({
6-
plugins: [million()],
6+
plugins: [million({ skipOptimize: true })],
77
});

0 commit comments

Comments
 (0)