Skip to content

Commit 328f9fe

Browse files
Refactor SVG src assignment in componentWillLoad
Replaces repetitive property checks with a loop to assign SVG source properties to imageState, improving code maintainability and readability.
1 parent 3e64d36 commit 328f9fe

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/frontend/components/django-hstore-widget/django-hstore-widget.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,12 @@ export class DjangoHstoreWidget {
5151

5252
// Callbacks
5353
async componentWillLoad() {
54-
if (this.delete_svg_src) {
55-
imageState.delete_svg_src = this.delete_svg_src;
56-
}
57-
if (this.add_svg_src) {
58-
imageState.add_svg_src = this.add_svg_src;
59-
}
60-
if (this.edit_svg_src) {
61-
imageState.edit_svg_src = this.edit_svg_src;
62-
}
54+
const props = ['delete_svg_src', 'add_svg_src', 'edit_svg_src'] as const;
55+
props.forEach(key => {
56+
if (this[key]) {
57+
imageState[key] = this[key];
58+
}
59+
});
6360
}
6461

6562
async componentDidLoad() {

0 commit comments

Comments
 (0)