Skip to content

Commit 7ca04f0

Browse files
committed
improve the dojo keyed implementation
1 parent e88368b commit 7ca04f0

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

frameworks/keyed/dojo/src/App.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { create, v, w } from '@dojo/framework/core/vdom';
2-
import Row from './Row';
2+
import RowContainer from './RowContainer';
33
import Buttons from './Buttons';
44
import store from './Store';
55

@@ -16,18 +16,18 @@ export default factory(function App({ middleware: { store }}) {
1616
{ id: 'swaprows', label: 'Swap Rows', onClick: store.swapRows }
1717
];
1818

19-
const rows = store.ids.map((id) => {
20-
return w(Row, {
21-
id,
22-
key: id,
19+
const rows = store.chunks().map((ids, i) => {
20+
return w(RowContainer, {
21+
ids,
22+
key: i,
2323
onSelect: store.select
2424
});
2525
});
2626

2727
return v('div', { key: 'root', classes: [ 'container' ] }, [
2828
w(Buttons, { buttonConfigs }),
2929
v('table', { classes: [ 'table', 'table-hover', 'table-striped', 'test-data' ] }, [
30-
v('tbody', rows)
30+
rows.length ? v('tbody', rows) : null
3131
]),
3232
v('span', { classes: [ 'preloadicon', 'glyphicon', 'glyphicon-remove' ] })
3333
]);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { create, w } from '@dojo/framework/core/vdom';
2+
import Row from './Row';
3+
4+
export interface RowContainerProperties {
5+
ids: string;
6+
onSelect: any;
7+
}
8+
9+
const factory = create().properties<RowContainerProperties>();
10+
11+
export default factory(function RowContainer({ properties }) {
12+
const { ids, onSelect } = properties();
13+
console.count('container');
14+
return (JSON.parse(ids) as number[]).map((id: number) => {
15+
return w(Row, {
16+
id,
17+
key: id,
18+
onSelect
19+
});
20+
});
21+
});

frameworks/keyed/dojo/src/Store.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ export default factory(({ properties, middleware: { invalidator }}) => {
115115
get ids(): number[] {
116116
return Array.from(ids);
117117
},
118+
chunks(size = 500): string[] {
119+
const ids = this.ids;
120+
const chunks: string[] =[];
121+
for (let i = 0; i< ids.length; i+=size) {
122+
chunks.push(JSON.stringify(ids.slice(i,i+size)));
123+
}
124+
return chunks;
125+
},
118126
get item(): Item | undefined {
119127
return data[widgetKey];
120128
},

0 commit comments

Comments
 (0)