Return promises and/or accept callbacks for all async methods
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
Most of the maps I'm working on at the moment have the basic pattern:
- load a basemap from Mapbox (either a standard one, or slightly tweaked)
- add stuff to it with Mapbox-GL-JS, such as a GeoJSON specified by URL
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.
2. Fetch the GeoJSON yourself (in parallel), and then add it when the map is ready. You probably end up adding D3-request or similar. Then you end up with this annoying code:
```
if (map.loaded())
map.addSource(...);
else
map.on('load', () => map.addSource(...));
```
Is there an inherent reason `map` can't accept new sources while it's loading?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the map load lifecycle and the async methods discussed in the issue; no files or tests are named. Compare the requested promise or callback behavior with the current source-loading flow, and consider the work done when the agreed API supports the affected async methods during loading.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100