mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2026-03-13 08:41:05 +08:00
refactor(graphic): simplify update and collector interfaces
This commit is contained in:
@@ -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"] });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -126,9 +126,7 @@ describe("graphic runtime", () => {
|
||||
await flushMicrotasks();
|
||||
|
||||
expect(requestUpdate).toHaveBeenCalledWith({
|
||||
updateOptions: {
|
||||
replaceMerge: ["graphic"],
|
||||
},
|
||||
replaceMerge: ["graphic"],
|
||||
});
|
||||
|
||||
const chart1 = {
|
||||
|
||||
@@ -376,7 +376,6 @@ describe("graphic", () => {
|
||||
sourceId: 2,
|
||||
});
|
||||
collector.unregister("node");
|
||||
collector.requestFlush();
|
||||
await flushMicrotasks();
|
||||
|
||||
expect(Array.from(collector.getNodes())).toEqual([]);
|
||||
|
||||
Reference in New Issue
Block a user