mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2026-03-13 08:41:05 +08:00
fix(update): keep migrated keys when option shape changes
This commit is contained in:
@@ -181,7 +181,12 @@ function collectObjectOverrides(prev: Signature, next: Signature): Map<string, n
|
||||
|
||||
const missingObjects = diffKeys(prev.objects, next.objects);
|
||||
for (let i = 0; i < missingObjects.length; i++) {
|
||||
overrides.set(missingObjects[i], null);
|
||||
const key = missingObjects[i];
|
||||
const movedToArray = next.arrays[key] !== undefined;
|
||||
const movedToScalar = next.scalars.includes(key);
|
||||
if (!movedToArray && !movedToScalar) {
|
||||
overrides.set(key, null);
|
||||
}
|
||||
}
|
||||
|
||||
return overrides;
|
||||
|
||||
@@ -418,6 +418,67 @@ describe("smart-update", () => {
|
||||
expect(result.plan.notMerge).toBe(false);
|
||||
expect(result.plan.replaceMerge).toBeUndefined();
|
||||
});
|
||||
|
||||
it("handles single-object series shape without array replacement planning", () => {
|
||||
const base: EChartsOption = {
|
||||
series: {
|
||||
type: "line",
|
||||
data: [1, 2, 3],
|
||||
} as unknown as EChartsOption["series"],
|
||||
};
|
||||
|
||||
const update: EChartsOption = {
|
||||
series: {
|
||||
type: "line",
|
||||
data: [2, 3, 4],
|
||||
} as unknown as EChartsOption["series"],
|
||||
};
|
||||
|
||||
const result = planUpdate(buildSignature(base), update);
|
||||
|
||||
expect(result.plan.notMerge).toBe(false);
|
||||
expect(result.plan.replaceMerge).toBeUndefined();
|
||||
expect(result.option.series).toEqual(update.series);
|
||||
});
|
||||
|
||||
it("keeps next series array when migrating from single-object series", () => {
|
||||
const base: EChartsOption = {
|
||||
series: {
|
||||
type: "bar",
|
||||
data: [10, 20],
|
||||
} as unknown as EChartsOption["series"],
|
||||
};
|
||||
|
||||
const update: EChartsOption = {
|
||||
series: [{ id: "latte", type: "bar", data: [12, 24] }],
|
||||
};
|
||||
|
||||
const result = planUpdate(buildSignature(base), update);
|
||||
|
||||
expect(result.plan.notMerge).toBe(false);
|
||||
expect(result.option.series).toEqual(update.series);
|
||||
expect(result.option.series).not.toBeNull();
|
||||
});
|
||||
|
||||
it("prioritizes notMerge when scalar removal happens with array shrink", () => {
|
||||
const base: EChartsOption = {
|
||||
color: "#000",
|
||||
series: [
|
||||
{ id: "a", type: "line", data: [1] },
|
||||
{ id: "b", type: "line", data: [2] },
|
||||
],
|
||||
};
|
||||
|
||||
const update: EChartsOption = {
|
||||
series: [{ id: "a", type: "line", data: [3] }],
|
||||
};
|
||||
|
||||
const result = planUpdate(buildSignature(base), update);
|
||||
|
||||
expect(result.plan.notMerge).toBe(true);
|
||||
expect(result.plan.replaceMerge).toBeUndefined();
|
||||
expect(result.option.series).toEqual(update.series);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user