| 436 | } |
| 437 | |
| 438 | class Cached { |
| 439 | constructor(mapping) { |
| 440 | this.mapping = mapping |
| 441 | this.work = Object.create(null) |
| 442 | this.done = Object.create(null) |
| 443 | } |
| 444 | |
| 445 | compute(value) { |
| 446 | return this.work[value] || (this.work[value] = this.mapping(value).then(result => this.done[value] = result)) |
| 447 | } |
| 448 | |
| 449 | store(value, result) { |
| 450 | this.work[value] = Promise.resolve(result) |
| 451 | return this.done[value] = result |
| 452 | } |
| 453 | |
| 454 | get(value) { |
| 455 | return this.done[value] |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | // Cache for loaded code and resolved unpkg redirects |
| 460 | const resolved = new Cached(name => fetch("https://unpkg.com/" + name.replace(/\/$/, "")).then(resp => { |
nothing calls this directly
no outgoing calls
no test coverage detected