Skip to content

feat(core, widgets): Allow widgets to modify views #9572

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ibgreen
Copy link
Collaborator

@ibgreen ibgreen commented Apr 10, 2025

Closes #

Background

  • Enable widgets to modify views
  • Enables a fully declarative (pydeck, json, ...) SplitterWidget, and many more potential use cases.

Change List

  • Hook widgets into the deck.gl needsUpdate cycle
  • Remove custom view updates in the widget demo app

splitter-widget

@ibgreen ibgreen marked this pull request as ready for review April 10, 2025 16:59
Copy link
Collaborator

@felixpalmer felixpalmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really like the idea, just think we need to be careful about the API

if (view1Index !== -1 && view2Index !== -1) {
views = [...views];
const [viewProps1, viewProps2] = getViewPropsForSplitRatio(this.splitRatio);
views[view1Index] = cloneView(views[view1Index], viewProps1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add clone() to the View class, for consistency with Layer`?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add clone() to the View class, for consistency with Layer`?

Yes, that would be the "natural thing" to do. But for the purposes of keeping this PR small and attract as few tangential discussions as possible, I left that our for now.

Added a TODO comment.

this._widgetManager!.setNeedsRedraw('SplitterWidget');
};

filterViews(views: View[]): View[] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To contrast with thelayerFilter API which is Layer => boolean, I wonder if this pattern is too powerful. If this function is implemented to add a view on every frame, will that make the number of view grow indefinitely?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if this pattern is too powerful. If this function is implemented to add a view on every frame, will that make the number of view grow indefinitely?

  • As you can see it replaces the existing views created by the app with clones, it does not add views.
  • If a widget wanted to add a view, it would do so with a specific id, and check for the presence of that id and only add if not already present.
  • This setup does not add a view / filter views every frame. When the ratio changes, a flag is set that is cleared after the filtering is done.

@coveralls
Copy link

Coverage Status

coverage: 91.623% (-0.01%) from 91.636%
when pulling c30e62c on ib/filter-views
into 91ccee6 on master.

Copy link
Collaborator

@chrisgervang chrisgervang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The majority of these changes are an easy stamp but of course this is the interesting one to discuss:

Hook widgets into the deck.gl needsUpdate cycle

Is this an ordered cycle, and if so, where is widgets in relation to other updates?

Are there any environments, like Mapbox integration, where this breaks?

If it's the last update in the cycle, does that mean the widget code gets the "final say" on state?

@@ -33,6 +35,7 @@ export abstract class WidgetImpl<PropsT extends WidgetImplProps> implements Widg
this.props = props;
}

onWidgetInitialized(): void {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be useful to add a lifecycle hook to the core widget interface that gets called by the manager after the widget is added to the DOM.

The existing hook, onAdd, is called prior to DOM mount, which makes sense but is quite limiting to the theme widget in particular since the widget needs to initialize its theme after it's mounted to the DOM (since it's a DOM mutation).

While this splitter widget isn't mutating the DOM, it seems the spirit of onWidgetInitialized is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants