// @ts-check /** * @import { CacheKey, CacheValue } from "./Cache.mjs" * @import LoadingCacheValue from "./LoadingCacheValue.mjs" */ /** * Loading store. * @see {@link LoadingEventMap `LoadingEventMap`} for a map of possible events. */ export default class Loading extends EventTarget { constructor() { super(); /** * Store of loading {@link CacheKey cache keys} and associated * {@link LoadingCacheValue loading cache values}. Multiple for the same key * are set in the order loading started. * @type {{ [cacheKey: CacheKey]: Set }} */ this.store = {}; } } /** * Map of possible {@linkcode Loading} events. Note that the keys don’t match * the dispatched event names that dynamically contain the associated * {@link CacheKey cache key}. * @typedef {object} LoadingEventMap * @prop {CustomEvent} start Signals the start of * {@link LoadingCacheValue loading a cache value}. The event name starts with * the {@link CacheKey cache key}, followed by `/start`. * @prop {CustomEvent} end Signals the end of * {@link LoadingCacheValue loading a cache value}; either the loading * finished and the {@link CacheValue cache value} was set, the loading was * aborted, or there was an error. The event name starts with the * {@link CacheKey cache key}, followed by `/end`. */ /** * @typedef {object} LoadingEventStartDetail * @prop {LoadingCacheValue} loadingCacheValue Loading cache value that started. */ /** * @typedef {object} LoadingEventEndDetail * @prop {LoadingCacheValue} loadingCacheValue Loading cache value that ended. */