-
Notifications
You must be signed in to change notification settings - Fork 2.1k
chore(widgets): Encapsulate the hacky / complex setViewState() #9596
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm favorable of adding a utility. View state isn't relevant to all widgets so we could also consider a ViewStateWidget subclass.
Requesting changes since the code looks broken in a few places
@@ -95,31 +92,6 @@ export class GeolocateWidget extends Widget<GeolocateWidgetProps> { | |||
handleCoordinates = coordinates => { | |||
this.setViewState(coordinates); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is broken
const viewId = this.props.viewId || (viewState?.id as string) || 'default-view'; | ||
const viewport = this.viewports[viewId] || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is necessary in widget that set view state
onViewportChange(viewport: Viewport) { | ||
this.viewports[viewport.id] = viewport; | ||
} | ||
|
||
viewports: Record<string, Viewport> = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep
@@ -61,18 +64,10 @@ export class ResetViewWidget extends Widget<ResetViewWidgetProps> { | |||
|
|||
handleClick() { | |||
const initialViewState = this.props.initialViewState || this.deck?.props.initialViewState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really ought to combine what this widget does and what compass widget does so that they can be used in either mode (initialViewState/viewState)
A user managing viewState would be able to use this widget too if we made homeViewState
a widget prop, and stored viewports
in the widget like the others.
In compass, we don't need to expose a prop but just check if initialViewState
is in use.
* @note this code abuses protected methods and should be refactored, | ||
* but does work for now until we have a cleaner solutions. | ||
*/ | ||
setViewState({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make protected?
Closes #
Background
For discussion
TODO -
Change List