Skip to content

Commit f6f82fa

Browse files
author
Akos Kitta
committed
fix: split up component rendering
Signed-off-by: Akos Kitta <[email protected]>
1 parent 56fbd39 commit f6f82fa

File tree

5 files changed

+252
-168
lines changed

5 files changed

+252
-168
lines changed

Diff for: arduino-ide-extension/src/browser/widgets/component-list/component-list-item.tsx

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from '@theia/core/shared/react';
2+
import type { ArduinoComponent } from '../../../common/protocol/arduino-component';
23
import { Installable } from '../../../common/protocol/installable';
3-
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
4-
import { ListItemRenderer } from './list-item-renderer';
4+
import type { ListItemRenderer } from './list-item-renderer';
55

66
export class ComponentListItem<
77
T extends ArduinoComponent
@@ -28,18 +28,22 @@ export class ComponentListItem<
2828
}
2929

3030
private async install(item: T): Promise<void> {
31-
this.setState({ state: 'uninstalling' });
32-
try {
33-
await this.props.install(item, this.state.selectedVersion);
34-
} finally {
35-
this.setState({ state: undefined });
36-
}
31+
await this.withState('installing', () =>
32+
this.props.install(item, this.state.selectedVersion)
33+
);
3734
}
3835

3936
private async uninstall(item: T): Promise<void> {
40-
this.setState({ state: 'uninstalling' });
37+
await this.withState('uninstalling', () => this.props.uninstall(item));
38+
}
39+
40+
private async withState(
41+
state: 'installing' | 'uninstalling',
42+
task: () => Promise<unknown>
43+
): Promise<void> {
44+
this.setState({ state });
4145
try {
42-
await this.props.uninstall(item);
46+
await task();
4347
} finally {
4448
this.setState({ state: undefined });
4549
}

Diff for: arduino-ide-extension/src/browser/widgets/component-list/component-list.tsx

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from '@theia/core/shared/react';
2-
import { ItemContent, Virtuoso } from '@theia/core/shared/react-virtuoso';
2+
import { Virtuoso } from '@theia/core/shared/react-virtuoso';
33
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
44
import { Installable } from '../../../common/protocol/installable';
55
import { ComponentListItem } from './component-list-item';
@@ -9,25 +9,22 @@ export class ComponentList<T extends ArduinoComponent> extends React.Component<
99
ComponentList.Props<T>
1010
> {
1111
override render(): React.ReactNode {
12-
return <Virtuoso data={this.props.items} itemContent={this.itemContent} />;
13-
}
14-
15-
private readonly itemContent: ItemContent<T, unknown> = (
16-
index: number,
17-
item: T
18-
) => {
1912
return (
20-
<ComponentListItem<T>
21-
key={this.props.itemLabel(item)}
22-
item={item}
23-
itemRenderer={this.props.itemRenderer}
24-
install={this.props.install}
25-
uninstall={this.props.uninstall}
13+
<Virtuoso
14+
data={this.props.items}
15+
itemContent={(_: number, item: T) => (
16+
<ComponentListItem<T>
17+
key={this.props.itemLabel(item)}
18+
item={item}
19+
itemRenderer={this.props.itemRenderer}
20+
install={this.props.install}
21+
uninstall={this.props.uninstall}
22+
/>
23+
)}
2624
/>
2725
);
28-
};
26+
}
2927
}
30-
3128
export namespace ComponentList {
3229
export interface Props<T extends ArduinoComponent> {
3330
readonly items: T[];

Diff for: arduino-ide-extension/src/browser/widgets/component-list/item-action.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)