Skip to content

Commit 52eb0b7

Browse files
committed
fix: remove unnecessary hash comparison for view changes and use direct reference equality instead
1 parent 73c8269 commit 52eb0b7

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

packages/core/lib/utils/map-context-diff.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SAMPLE_LAYER4,
99
SAMPLE_LAYER5,
1010
} from "../../fixtures/map-context.fixtures";
11-
import { describe } from "vitest";
11+
import { describe, it, expect, beforeEach } from "vitest";
1212

1313
describe("Context diff utils", () => {
1414
describe("computeMapContextDiff", () => {
@@ -295,6 +295,37 @@ describe("Context diff utils", () => {
295295
});
296296
});
297297
});
298+
describe("same content but different reference", () => {
299+
beforeEach(() => {
300+
contextOld = {
301+
...SAMPLE_CONTEXT,
302+
view: {
303+
center: [5, 10],
304+
zoom: 3,
305+
},
306+
};
307+
contextNew = {
308+
...SAMPLE_CONTEXT,
309+
view: {
310+
center: [5, 10],
311+
zoom: 3,
312+
},
313+
};
314+
});
315+
it("output the correct diff", () => {
316+
diff = computeMapContextDiff(contextNew, contextOld);
317+
expect(diff).toEqual({
318+
layersAdded: [],
319+
layersChanged: [],
320+
layersRemoved: [],
321+
layersReordered: [],
322+
viewChanges: {
323+
center: [5, 10],
324+
zoom: 3,
325+
},
326+
});
327+
});
328+
});
298329
});
299330

300331
describe("combined changes", () => {

packages/core/lib/utils/map-context-diff.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
MapContextLayerReordered,
77
} from "../model";
88
import { isLayerSame, isLayerSameAndUnchanged } from "./map-context";
9-
import { getHash } from "./hash";
109

1110
/**
1211
* The following logic is produced by identifying layers in both context
@@ -92,9 +91,7 @@ export function computeMapContextDiff(
9291
}
9392

9493
let viewChanges =
95-
getHash(nextContext.view) !== getHash(previousContext.view)
96-
? nextContext.view
97-
: undefined;
94+
nextContext.view !== previousContext.view ? nextContext.view : undefined;
9895
if (viewChanges !== null && viewChanges !== undefined) {
9996
viewChanges = { ...viewChanges }; // copy the view to avoid unexpected mutations
10097
}

0 commit comments

Comments
 (0)