refactor: extract magic constants — wave 3 (font lifecycle)
Promote font-loading scheduling and lifecycle tunables to named module-level constants: - comparisonStore: FONT_READY_FALLBACK_MS (1000ms) — UI unblock safety net - fontLifecycleManager: - PURGE_INTERVAL_MS (60000) — periodic eviction sweep - IDLE_CALLBACK_TIMEOUT_MS (150) — requestIdleCallback timeout - SCHEDULE_FALLBACK_MS (16) — setTimeout fallback (~60fps) - YIELD_INTERVAL_MS (8) — parse-loop yield budget for non-Chromium - CRITICAL_FONT_WEIGHTS ([400, 700]) — data-saver allowlist - FontEvictionPolicy: DEFAULT_FONT_TTL_MS (5 minutes) - FontLoadQueue: FONT_LOAD_MAX_RETRIES (3) No behavior changes — values preserved exactly. Class-private fields that mirrored these constants are removed in favor of module scope.
This commit is contained in:
+7
-2
@@ -1,6 +1,11 @@
|
||||
/**
|
||||
* Default TTL after which an unpinned font is eligible for eviction.
|
||||
*/
|
||||
export const DEFAULT_FONT_TTL_MS = 5 * 60 * 1000;
|
||||
|
||||
interface FontEvictionPolicyOptions {
|
||||
/**
|
||||
* TTL in milliseconds. Defaults to 5 minutes.
|
||||
* TTL in milliseconds. Defaults to {@link DEFAULT_FONT_TTL_MS}.
|
||||
*/
|
||||
ttl?: number;
|
||||
}
|
||||
@@ -17,7 +22,7 @@ export class FontEvictionPolicy {
|
||||
|
||||
readonly #TTL: number;
|
||||
|
||||
constructor({ ttl = 5 * 60 * 1000 }: FontEvictionPolicyOptions = {}) {
|
||||
constructor({ ttl = DEFAULT_FONT_TTL_MS }: FontEvictionPolicyOptions = {}) {
|
||||
this.#TTL = ttl;
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -1,5 +1,11 @@
|
||||
import type { FontLoadRequestConfig } from '../../../../types';
|
||||
|
||||
/**
|
||||
* Maximum number of times a single font key will be retried before it is
|
||||
* considered permanently failed.
|
||||
*/
|
||||
export const FONT_LOAD_MAX_RETRIES = 3;
|
||||
|
||||
/**
|
||||
* Manages the font load queue and per-font retry counts.
|
||||
*
|
||||
@@ -10,8 +16,6 @@ export class FontLoadQueue {
|
||||
#queue = new Map<string, FontLoadRequestConfig>();
|
||||
#retryCounts = new Map<string, number>();
|
||||
|
||||
readonly #MAX_RETRIES = 3;
|
||||
|
||||
/**
|
||||
* Adds a font to the queue.
|
||||
* @returns `true` if the key was newly enqueued, `false` if it was already present.
|
||||
@@ -52,7 +56,7 @@ export class FontLoadQueue {
|
||||
* Returns `true` if the font has reached or exceeded the maximum retry limit.
|
||||
*/
|
||||
isMaxRetriesReached(key: string): boolean {
|
||||
return (this.#retryCounts.get(key) ?? 0) >= this.#MAX_RETRIES;
|
||||
return (this.#retryCounts.get(key) ?? 0) >= FONT_LOAD_MAX_RETRIES;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user