Skip to content

Commit

Permalink
refactor: optimize species settings initialization in HTML templates
Browse files Browse the repository at this point in the history
- Replaced direct assignment of species data with asynchronous initialization methods for `allSpecies` and `filteredSpecies`.
- Updated `x-init` to call the new `init` function, ensuring data is loaded correctly before usage.
- This change improves the loading process and maintains the reactivity of the species settings component.
  • Loading branch information
tphakala committed Jan 14, 2025
1 parent eeb45c2 commit 9a37d82
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions views/settings/speciesSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
showTooltip: null,
hasChanges: false,
predictions: [],
allSpecies: {{getAllSpecies | toJSON}},
allSpecies: [],
async init() {
this.allSpecies = {{getAllSpecies | toJSON}};
},
speciesSettingsOpen: false,
showActionsModal: false,
currentSpecies: '',
Expand Down Expand Up @@ -50,7 +53,7 @@
.slice(0, 5);
},
}"
x-init="$watch('speciesSettings', () => { hasChanges = true }, { deep: true })"
x-init="init(); $watch('speciesSettings', () => { hasChanges = true }, { deep: true })"
x-cloak>

<input type="checkbox"
Expand Down Expand Up @@ -132,7 +135,10 @@
showTooltip: null,
hasChanges: false,
predictions: [],
filteredSpecies: {{getIncludedSpecies | toJSON}},
filteredSpecies: [],
async init() {
this.filteredSpecies = {{getIncludedSpecies | toJSON}};
},
resetChanges() {
this.hasChanges = false;
},
Expand Down Expand Up @@ -164,7 +170,7 @@
.slice(0, 5);
},
}"
x-init="$watch('speciesSettings', () => { hasChanges = true }, { deep: true })"
x-init="init(); $watch('speciesSettings', () => { hasChanges = true }, { deep: true })"
x-cloak>

<input type="checkbox"
Expand Down Expand Up @@ -240,8 +246,12 @@
showTooltip: null,
hasChanges: false,
predictions: [],
allSpecies: {{getAllSpecies | toJSON}},
filteredSpecies: {{getIncludedSpecies | toJSON}},
allSpecies: [],
filteredSpecies: [],
async init() {
this.allSpecies = {{getAllSpecies | toJSON}};
this.filteredSpecies = {{getIncludedSpecies | toJSON}};
},
speciesSettingsOpen: false,
showActionsModal: false,
currentSpecies: '',
Expand Down Expand Up @@ -334,7 +344,7 @@
.slice(0, 5);
},
}"
x-init="$watch('speciesSettings', () => { hasChanges = true }, { deep: true })"
x-init="init(); $watch('speciesSettings', () => { hasChanges = true }, { deep: true })"
x-cloak>

<input type="checkbox"
Expand Down

0 comments on commit 9a37d82

Please sign in to comment.