-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 promises and/or accept callbacks for all async methods #3964
Comments
We just discussed this in #2792. Personally I believe there should be at least two well defined states that are exposed via the API and signalled via events, but perhaps three:
As elaborated a bit on in #2792 it might be tricky (and meaningless?) to distinguish between 2 and 3 since transitions inherently triggers tile fetching which also means that it is loading. |
Ah, thanks. Yeah, basically I'd like to be able to add sources after Also, any way to clean up the
|
Renamed this ticket to focus on the underlying challenge:
This is a real problem that deserves a good solution. Some ideas:
|
Some thoughts here: Error handling would have to be async and might get harder in a bad wayAllowing access to more methods before the map's style loads would require rethought error handling: for instance, if you allow someone to call The proposals of
|
Hmm, good points. I'm used to working with promises, so that seemed natural to me - less familiar with
This situation actually seems a bit messy even in promise-land: |
Methods that are candidates:
Methods that are candidates but will be replaced by the unified
|
The only thing I want to add is don't bother with callbacks so you don't need to make the api more complicated than necessary. Using callbacks instead of promises should be avoided unless somebody can convince the majority, which I hope that doesn't happen :) There are plenty of polyfils for promises if a user wants to go back to the stone age :P |
Any progress on this one? How can I know when my panBy or easeTo are finished? Can we use promises now? |
You can subscribe to the map.easeTo(...).once('moveend', () => { ... }); |
I've created a library for this case: map-promisified. I have two questions concerning this issue:
Thank you! |
I wanted to be able to say something like |
@barraponto This ticket is tracking the first part of your request.
Could you open a separate tickets for the above. With some additional information on how you would expect this to work and how you would like to use it. |
I've been using:
Which seems to be working. Adding a tag after the map would make it general for all map events. Is there any reason this sort of thing would fail in mapbox? Tnx! |
Any idea when the The current hack I'm using is a combination of using the is there any other ways to figure out if filtering is completed? I tried inspecting some of the private member variables but wasn't super clear. |
Most of the maps I'm working on at the moment have the basic pattern:
But you can't add stuff to the map until it's fully loaded. So you either:
1: Wait for the map to load, then add the source by URL. This is slow, and misses out on the opportunity to do the two network requests in parallel.
Is there an inherent reason
map
can't accept new sources while it's loading?The text was updated successfully, but these errors were encountered: