global player pt. 3 persistence shenanigans
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
nowPlayingLabel,
|
nowPlayingLabel,
|
||||||
prev,
|
prev,
|
||||||
removeTrack,
|
removeTrack,
|
||||||
|
schedulePersistNow,
|
||||||
setUiOpen,
|
setUiOpen,
|
||||||
setVolume,
|
setVolume,
|
||||||
toggleShuffle,
|
toggleShuffle,
|
||||||
@@ -151,6 +152,11 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
media.setTrack(snap.currentTrack);
|
media.setTrack(snap.currentTrack);
|
||||||
|
|
||||||
|
// Persist queue/settings/UI state (throttled) from within a component-scoped effect
|
||||||
|
// to avoid orphaned module-level `$effect`.
|
||||||
|
schedulePersistNow();
|
||||||
|
|
||||||
if (!audioEl) return;
|
if (!audioEl) return;
|
||||||
|
|
||||||
audioEl.volume = snap.volume;
|
audioEl.volume = snap.volume;
|
||||||
|
|||||||
@@ -154,12 +154,19 @@ const snapshot = $derived<PlayerSnapshot>({
|
|||||||
uiOpen,
|
uiOpen,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Persist on changes (best effort, throttled). */
|
/**
|
||||||
|
* Persistence
|
||||||
|
*
|
||||||
|
* NOTE: Module-level `$effect` is not allowed (it becomes an "orphaned effect").
|
||||||
|
* Instead, the GlobalPlayer component (or any single always-mounted component)
|
||||||
|
* should call `schedulePersistNow()` inside its own `$effect`.
|
||||||
|
*/
|
||||||
const schedulePersist = createPersistScheduler(250);
|
const schedulePersist = createPersistScheduler(250);
|
||||||
$effect(() => {
|
|
||||||
|
export function schedulePersistNow(): void {
|
||||||
if (!browser) return;
|
if (!browser) return;
|
||||||
schedulePersist(persistableState());
|
schedulePersist(persistableState());
|
||||||
});
|
}
|
||||||
|
|
||||||
/** --- Public reads --- */
|
/** --- Public reads --- */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user