import {LRUCache} from 'lru-cache'; import Ecs from '@/ecs/ecs.js'; import {withResolvers} from '@/util/promise.js'; const cache = new LRUCache({ max: 128, }); export default class ClientEcs extends Ecs { async readAsset(uri) { if (!cache.has(uri)) { const {promise, resolve, reject} = withResolvers(); cache.set(uri, promise); fetch(new URL(uri, window.location.origin)) .then(async (response) => { resolve(response.ok ? response.arrayBuffer() : new ArrayBuffer(0)); }) .catch(reject); } return cache.get(uri); } }