mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
common/ had become the backend's library: 30 of its 41 modules were imported by nothing in the frontend, so the name no longer said what belonged there. It now holds only what the frontend or the build imports too; backend-only code moved to server/, flat except for datasets/ (the dataset engine and its readers). The *-db/ dataset directories stay in common/: self-hosting docs and Docker volumes mount those paths. frontend/utils/ keeps its app-wide modules at the root and gains ip/ (IP / ASN shaping and validation), report/ (the report pipeline) and features/ (the pure layer of a single feature). Paths only — no logic changes. The Dockerfile copies server/, and the AGENTS.md files say where a new module goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
// Serialize lazy world-map renders. Hide skips new work but keeps a live
|
|
// chart on its canvas so a closing animation can finish; destroy when the
|
|
// canvas leaves or the scope is disposed.
|
|
import { ref, watch, onScopeDispose, toValue } from 'vue';
|
|
import { renderWorldMapChart } from '../utils/features/world-map-chart.js';
|
|
|
|
export const useWorldMapChart = ({ canvas, visible, options, theme }, { render = renderWorldMapChart } = {}) => {
|
|
const ready = ref(false);
|
|
const failed = ref(false);
|
|
let chart = null;
|
|
let queue = Promise.resolve();
|
|
let generation = 0;
|
|
let disposed = false;
|
|
|
|
const destroy = () => {
|
|
chart?.destroy();
|
|
chart = null;
|
|
ready.value = false;
|
|
};
|
|
|
|
watch([canvas, visible, options, () => toValue(theme)], () => {
|
|
const current = ++generation;
|
|
if (!toValue(canvas)) {
|
|
failed.value = false;
|
|
destroy();
|
|
return;
|
|
}
|
|
if (!toValue(visible)) return;
|
|
failed.value = false;
|
|
queue = queue.then(async () => {
|
|
const isActive = () => !disposed && current === generation;
|
|
if (!isActive()) return;
|
|
try {
|
|
const next = await render({ ...toValue(options), canvas: toValue(canvas), chart, isActive });
|
|
if (!isActive()) {
|
|
if (next && next !== chart) next.destroy();
|
|
return;
|
|
}
|
|
chart = next;
|
|
ready.value = Boolean(chart);
|
|
failed.value = !chart;
|
|
} catch {
|
|
if (isActive()) {
|
|
destroy();
|
|
failed.value = true;
|
|
}
|
|
}
|
|
});
|
|
}, { immediate: true, flush: 'post' });
|
|
|
|
onScopeDispose(() => {
|
|
disposed = true;
|
|
generation += 1;
|
|
destroy();
|
|
});
|
|
|
|
return { ready, failed };
|
|
};
|