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

Add hasControl method #10035

Merged
merged 3 commits into from
Oct 21, 2020
Merged

Add hasControl method #10035

merged 3 commits into from
Oct 21, 2020

Conversation

tristen
Copy link
Member

@tristen tristen commented Oct 15, 2020

Launch Checklist

Adds a hasControl method to src/ui/map.js so clients can detect whether a control already exists before calling addControl or removeControl.

  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page
  • tagged @mapbox/map-design-team @mapbox/static-apis if this PR includes style spec API or visual changes
  • tagged @mapbox/gl-native if this PR includes shader changes or needs a native port
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Adds a hasControl method to map</changelog>

Copy link
Contributor

@ryanhamley ryanhamley left a comment

Choose a reason for hiding this comment

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

Looks good, except I think we can just rely on returning true or false rather than throwing an error

src/ui/map.js Outdated
Comment on lines 572 to 575
if (!control || typeof control !== 'object') {
return this.fire(new ErrorEvent(new Error(
'Invalid argument to map.hasControl(). Argument must be a control.')));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is really necessary. An undefined value or something that isn't an object would return false which I think is sufficient

@tristen tristen merged commit ff8e087 into main Oct 21, 2020
@tristen tristen deleted the hasControl-method branch October 21, 2020 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants