refactor(graphic): simplify update and collector interfaces

This commit is contained in:
Justineo
2026-02-09 02:11:54 +08:00
committed by GU Yiling
parent f702eb7733
commit c72eeb30d8
6 changed files with 8 additions and 15 deletions

View File

@@ -90,7 +90,7 @@ export default defineComponent({
const nativeListeners: Record<string, unknown> = {};
const listeners: Array<{ event: string; once?: boolean; zr?: boolean; handler: any }> = [];
const hasGraphicSlot = (): boolean => Boolean((slots as Record<string, unknown>).graphic);
const hasGraphicSlot = Boolean((slots as Record<string, unknown>).graphic);
const { teleportedSlots, patchOption } = useSlotOption(slots, () => {
if (!manualUpdate.value && props.option && chart.value) {
@@ -100,14 +100,14 @@ export default defineComponent({
let lastSignature: Signature | undefined;
const requestUpdate = (options?: { updateOptions?: UpdateOptions }): boolean => {
const requestUpdate = (updateOptions?: UpdateOptions): boolean => {
if (!chart.value || !props.option) {
return false;
}
if (manualUpdate.value) {
return false;
}
applyOption(chart.value, props.option, options?.updateOptions);
applyOption(chart.value, props.option, updateOptions);
return true;
};
@@ -119,7 +119,7 @@ export default defineComponent({
warn,
});
if (hasGraphicSlot() && !graphicRuntime) {
if (hasGraphicSlot && !graphicRuntime) {
warn(warnMissingGraphicEntry());
}
@@ -338,7 +338,7 @@ export default defineComponent({
if (instance) {
instance.setTheme(theme || {});
if (hasGraphicSlot() && props.option && !manualUpdate.value) {
if (hasGraphicSlot && props.option && !manualUpdate.value) {
applyOption(instance, props.option, { replaceMerge: ["graphic"] });
}
}

View File

@@ -16,7 +16,6 @@ export type GraphicCollector = {
unregister: (id: string, sourceId?: number) => void;
warnOnce: (key: string, message: string) => void;
getNodes: () => Iterable<GraphicNode>;
requestFlush: () => void;
dispose: () => void;
};
@@ -116,7 +115,6 @@ export function createGraphicCollector(options: {
unregister,
warnOnce,
getNodes,
requestFlush,
dispose,
};
}

View File

@@ -127,9 +127,7 @@ export function registerGraphicExtension(): void {
graphicOption = buildGraphicOption(nodes, ROOT_ID);
const updated = ctx.requestUpdate({
updateOptions: {
replaceMerge: ["graphic"],
},
replaceMerge: ["graphic"],
});
if (!updated && ctx.manualUpdate.value) {

View File

@@ -2,7 +2,7 @@ import type { Ref, Slots, VNodeChild } from "vue";
import type { EChartsType, Option, UpdateOptions } from "../types";
export type GraphicRequestUpdate = (options?: { updateOptions?: UpdateOptions }) => boolean;
export type GraphicRequestUpdate = (updateOptions?: UpdateOptions) => boolean;
export type GraphicRuntimeContext = {
chart: Ref<EChartsType | undefined>;

View File

@@ -126,9 +126,7 @@ describe("graphic runtime", () => {
await flushMicrotasks();
expect(requestUpdate).toHaveBeenCalledWith({
updateOptions: {
replaceMerge: ["graphic"],
},
replaceMerge: ["graphic"],
});
const chart1 = {

View File

@@ -376,7 +376,6 @@ describe("graphic", () => {
sourceId: 2,
});
collector.unregister("node");
collector.requestFlush();
await flushMicrotasks();
expect(Array.from(collector.getNodes())).toEqual([]);