Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor changing view controller type. #7814

Merged
merged 10 commits into from
May 23, 2023
5 changes: 3 additions & 2 deletions modules/core/src/lib/view-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ export default class ViewManager {
height: viewport.height
};

// TODO - check if view / controller type has changed, and replace the controller
if (!controller) {
// Create controller if not already existing or if the type of the
// controller has changed.
if (!controller || controller.constructor !== view.ControllerType) {
controller = this._createController(view, resolvedProps);
}
if (controller) {
Expand Down
32 changes: 31 additions & 1 deletion test/modules/core/views/view-manager.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'tape-promise/tape';
import ViewManager from '@deck.gl/core/lib/view-manager';
import {MapView, Viewport} from 'deck.gl';
import {OrbitController, OrbitView, MapController, MapView, Viewport} from 'deck.gl';

const INITIAL_VIEW_STATE = {latitude: 0, longitude: 0, zoom: 1};

Expand Down Expand Up @@ -75,3 +75,33 @@ test('ViewManager#needsRedraw', t => {

t.end();
});

test('ViewManager#updateController', t => {
const viewManager = new ViewManager({});

const mapView = new MapView({id: 'test', height: '100%', controller: MapController});
viewManager.setProps({
views: [mapView],
viewState: INITIAL_VIEW_STATE,
width: 100,
height: 100
});

const mapController = viewManager.controllers['test'];
t.equals(mapController.constructor, MapController, 'Correct controller type');

// Replace the MapView with a new OrbitView, given the same id.
const orbitView = new OrbitView({id: 'test', height: '100%', controller: OrbitController});
viewManager.setProps({
views: [orbitView],
viewState: INITIAL_VIEW_STATE,
width: 100,
height: 100
});

// Verify that the new view has the correct controller.
const orbitController = viewManager.controllers['test'];
t.equals(orbitController.constructor, OrbitController, 'Correct controller type');

t.end();
});