@razz21/vue-scan
Version:
Track and visualize Vue 3 component renders
56 lines (55 loc) • 1.33 kB
JavaScript
import { logger as i } from "../utils/logger.js";
import { getComponentElement as c, getComponentName as d, isRootComponent as a } from "./utils.js";
class m {
store;
constructor() {
this.store = /* @__PURE__ */ new Map();
}
async getTrackedInstance(e) {
return new Promise((t) => {
const r = this.store.get(e.uid);
if (r)
return t(r);
const n = c(e), o = d(e);
if (!n?.isConnected)
return i.error(
`Failed to track component element for "${o}", received "${n}". Skipping.`
), t(void 0);
const s = {
name: o,
uid: e.uid,
el: new WeakRef(n),
instance: new WeakRef(e),
lastUpdated: 0,
renderCount: 0,
rect: n.getBoundingClientRect()
};
this.store.set(e.uid, s), t(s);
});
}
async trackRender(e) {
if (a(e)) return;
const t = await this.getTrackedInstance(e), r = t.el?.deref();
if (!r.isConnected) {
this.store.delete(e.uid);
return;
}
return t.rect = r.getBoundingClientRect(), t;
}
getStore() {
return this.store;
}
deleteElement(e) {
return this.store.delete(e);
}
getInstance(e) {
return this.store.get(e);
}
clear() {
this.store.clear();
}
}
export {
m as VueScanStore
};
//# sourceMappingURL=store.js.map