Skip to content

Commit

Permalink
feat(widgets): Remove onViewportChange Update Guard for Widgets (#9303
Browse files Browse the repository at this point in the history
)

* remove widget manager viewport optimization
  • Loading branch information
chrisgervang authored Dec 19, 2024
1 parent 05bca74 commit 2374bc7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 2 additions & 6 deletions modules/core/src/lib/widget-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,14 @@ export class WidgetManager {
acc[v.id] = v;
return acc;
}, {});
const {lastViewports} = this;

for (const widget of this.getWidgets()) {
const {viewId} = widget;
if (viewId) {
// Attached to a specific view
const viewport = viewportsById[viewId];
if (viewport) {
if (widget.onViewportChange && !viewport.equals(lastViewports[viewId])) {
if (widget.onViewportChange) {
widget.onViewportChange(viewport);
}
widget.onRedraw?.({viewports: [viewport], layers});
Expand All @@ -259,10 +258,7 @@ export class WidgetManager {
// Not attached to a specific view
if (widget.onViewportChange) {
for (const viewport of viewports) {
// eslint-disable-next-line max-depth
if (!viewport.equals(lastViewports[viewport.id])) {
widget.onViewportChange(viewport);
}
widget.onViewportChange(viewport);
}
}
widget.onRedraw?.({viewports, layers});
Expand Down
7 changes: 5 additions & 2 deletions modules/widgets/src/compass-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ export class CompassWidget implements Widget<CompassWidgetProps> {
}

onViewportChange(viewport: Viewport) {
this.viewports[viewport.id] = viewport;
this.update();
// no need to update if viewport is the same
if (!viewport.equals(this.viewports[viewport.id])) {
this.viewports[viewport.id] = viewport;
this.update();
}
}

onAdd({deck}: {deck: Deck<any>}): HTMLDivElement {
Expand Down
4 changes: 2 additions & 2 deletions test/modules/core/lib/widget-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ test('WidgetManager#onRedraw#without viewId', t => {
layers: []
});

t.is(onViewportChangeCalledCount, 1, 'widget.onViewportChange not called');
t.is(onViewportChangeCalledCount, 2, 'widget.onViewportChange called');
t.is(onRedrawCalledCount, 2, 'widget.onRedraw called');

widgetManager.onRedraw({
Expand All @@ -188,7 +188,7 @@ test('WidgetManager#onRedraw#without viewId', t => {
],
layers: []
});
t.is(onViewportChangeCalledCount, 3, 'widget.onViewportChange called');
t.is(onViewportChangeCalledCount, 4, 'widget.onViewportChange called');
t.is(onRedrawCalledCount, 3, 'widget.onRedraw called');

widgetManager.finalize();
Expand Down

0 comments on commit 2374bc7

Please sign in to comment.