refactor(date-picker): group selected-state declarations up top
selectedYear/selectedMonth were declared below selectDay, which writes to them, and below isToday, which is declared nearby. Runtime worked because the assignments only run on user click (after script init), but the split made the initialization order confusing. Group all $state fields at the top of the script.
This commit is contained in:
parent
62cf05480d
commit
c952156491
|
|
@ -13,6 +13,8 @@
|
|||
let viewYear = $state(existing ? existing.getFullYear() : now.getFullYear());
|
||||
let viewMonth = $state(existing ? existing.getMonth() : now.getMonth());
|
||||
let selectedDay = $state(existing ? existing.getDate() : now.getDate());
|
||||
let selectedYear = $state(existing ? existing.getFullYear() : now.getFullYear());
|
||||
let selectedMonth = $state(existing ? existing.getMonth() : now.getMonth());
|
||||
let includeTime = $state(has_time);
|
||||
let selectedHour = $state(existing ? existing.getHours() : now.getHours());
|
||||
let selectedMinute = $state(existing ? existing.getMinutes() : 0);
|
||||
|
|
@ -58,9 +60,6 @@
|
|||
return `${viewYear}-${viewMonth + 1}-${day}` === todayStr;
|
||||
}
|
||||
|
||||
let selectedYear = $state(existing ? existing.getFullYear() : now.getFullYear());
|
||||
let selectedMonth = $state(existing ? existing.getMonth() : now.getMonth());
|
||||
|
||||
function isSelected(day: number): boolean {
|
||||
return selectedDay === day && selectedYear === viewYear && selectedMonth === viewMonth;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue