mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 06:25:41 +00:00
refactor(player): E.18 — extract three transport-coordination modules (#581)
Cluster of three small thematically-related cuts in one PR (per the new
'cluster, don't single-shot' convention):
- `src/store/seekTargetState.ts` — the seek-target guard (`seekTarget`,
`seekTargetSetAt`, `SEEK_TARGET_GUARD_TIMEOUT_MS`, set/clear/get
accessors) that suppresses stale Rust progress ticks until the
engine catches up to the requested position
- `src/store/togglePlayLock.ts` — the 300 ms double-click cooldown
behind a `tryAcquireTogglePlayLock()` helper that auto-releases on
a timer (collapses the three-line inline pattern in `togglePlay`)
- `src/store/loudnessReseed.ts` — the full `reseedLoudnessForTrackId`
pipeline (gen-bump → cache + backfill wipe → state reset → server
row delete → forced seed enqueue), pulled out of playerStore as a
single async helper
All three were file-private; no caller-side changes outside
playerStore's own imports. The progress handler's seek-guard branch is
now ~3 lines shorter and reads through accessors. `togglePlay` collapses
to one guard check.
24 tests across the three modules pin the API contracts.
playerStore 3189 → 3139 LOC.
This commit is contained in:
committed by
GitHub
parent
9029ab8ec5
commit
4c64844349
@@ -0,0 +1,47 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
_resetTogglePlayLockForTest,
|
||||
tryAcquireTogglePlayLock,
|
||||
} from './togglePlayLock';
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
_resetTogglePlayLockForTest();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe('tryAcquireTogglePlayLock', () => {
|
||||
it('returns true on first acquire', () => {
|
||||
expect(tryAcquireTogglePlayLock()).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false when already held', () => {
|
||||
tryAcquireTogglePlayLock();
|
||||
expect(tryAcquireTogglePlayLock()).toBe(false);
|
||||
});
|
||||
|
||||
it('auto-releases after the default 300 ms window', () => {
|
||||
tryAcquireTogglePlayLock();
|
||||
vi.advanceTimersByTime(299);
|
||||
expect(tryAcquireTogglePlayLock()).toBe(false);
|
||||
vi.advanceTimersByTime(1);
|
||||
expect(tryAcquireTogglePlayLock()).toBe(true);
|
||||
});
|
||||
|
||||
it('honours a custom lock duration', () => {
|
||||
tryAcquireTogglePlayLock(1000);
|
||||
vi.advanceTimersByTime(500);
|
||||
expect(tryAcquireTogglePlayLock()).toBe(false);
|
||||
vi.advanceTimersByTime(500);
|
||||
expect(tryAcquireTogglePlayLock()).toBe(true);
|
||||
});
|
||||
|
||||
it('_resetTogglePlayLockForTest force-releases', () => {
|
||||
tryAcquireTogglePlayLock();
|
||||
_resetTogglePlayLockForTest();
|
||||
expect(tryAcquireTogglePlayLock()).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user