push
travis-ci-com
1436 of 1440 branches covered (99.72%)
88 of 88 new or added lines in 12 files covered. (100.0%)
1909 of 1909 relevant lines covered (100.0%)
144.33 hits per line
1 |
const callbacks = new WeakMap();
|
2✔ |
2 |
const queue = new Set();
|
2✔ |
3 |
|
|
4 |
function execute() { |
|
5 |
try {
|
107✔ |
|
queue.forEach((target) => { |
107✔ |
7 |
try {
|
276✔ |
8 |
callbacks.get(target)(); |
276✔ |
9 |
queue.delete(target);
|
274✔ |
10 |
} catch (e) {
|
|
11 |
queue.delete(target);
|
2✔ |
12 |
throw e;
|
2✔ |
13 |
} |
|
14 |
}); |
|
15 |
} catch (e) {
|
|
16 |
if (queue.size) execute();
|
|
17 |
throw e;
|
2✔ |
18 |
} |
|
19 |
} |
|
20 |
|
|
21 |
export function dispatch(target) { |
|
22 |
if (callbacks.has(target)) {
|
|
23 |
if (!queue.size) {
|
|
24 |
requestAnimationFrame(execute); |
106✔ |
25 |
} |
|
26 |
queue.add(target); |
283✔ |
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
export function subscribe(target, cb) { |
|
31 |
callbacks.set(target, cb); |
213✔ |
32 |
dispatch(target); |
213✔ |
33 |
|
|
34 |
return function unsubscribe() { |
213✔ |
35 |
queue.delete(target);
|
199✔ |
36 |
callbacks.delete(target);
|
199✔ |
37 |
}; |
|
38 |
} |