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

Return a promise in "once" if no listener provided #10203

Merged
merged 2 commits into from
Jan 11, 2021
Merged

Return a promise in "once" if no listener provided #10203

merged 2 commits into from
Jan 11, 2021

Conversation

mourner
Copy link
Member

@mourner mourner commented Dec 14, 2020

Closes #10192. Now evented.once(eventName) now returns a promise if no listener function is provided (thanks @stevage for the suggestion!), allowing for ergonomic usage of async/await with GL JS while not breaking backwards compatibility:

(async () => {
  const map = new mapboxgl.Map(...);
  await map.once('load');
  map.addLayer(...);
  await map.once('idle');
})();

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • manually test the debug page
  • 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></changelog>

@mourner mourner requested a review from arindam1993 December 14, 2020 12:30
@mourner mourner self-assigned this Dec 14, 2020
@karimnaaji karimnaaji added this to the v2.1.0 milestone Jan 4, 2021
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.

This works well and is a nice incremental improvement. I just have a nit with the doc string.

src/util/evented.js Outdated Show resolved Hide resolved
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.

Introduce "await map.until(event)" syntax for easier async
3 participants