-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Loading.mjs
49 lines (43 loc) · 1.64 KB
/
Loading.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// @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<LoadingCacheValue> }}
*/
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<LoadingEventStartDetail>} 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<LoadingEventEndDetail>} 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.
*/