Comments (5)
from google-maps-services-js.
OK, I had a play with what things look like with promises, and it's much nicer. Then I had a play with what things look like using window.fetch
, and think this also makes a LOT of sense.
- A lot of thought has gone into
window.fetch
and promises/A+, and so if our API looks like it, it will probably be well-design and pleasant to use. It will also feel familiar in years to come ifwindow.fetch
gets widespread adoption. - It makes the implementation of our client library much easier to read.
I've been injecting the fetch function, so that the developer can supply their own fetch polyfill (for browser or node). That feels quite natural. You have inject your API key as well, so the injection step had to happen anyway.
Injecting the fetch function will also allow people to unit test against our client library. According to Michael Feathers, this is "the golden rule of API design" (97 Things Every Programmer Should Know, 2010).
from google-maps-services-js.
Another issue with Promises and window.fetch(): how do you cancel?
AFAICT, the community hasn't decided how this should be done.
This is pretty important for us, since the client library offers to rate-limit and automatically retry.
- In my opinion, promises ought not be cancelled... that's an oxymoron. I'm not a fan of the back-pressure idea either. AND
- The fetch spec doesn't allow cancelling today. BUT
- Our client library request could be cancelled, because rate-limiting or retrying might mean we haven't yet called
fetch()
.
Since our request function returns a promise, it will have to expose the cancelling mechanism via a revealing constructor. I imagine it looking like this:
var cancelGeocode;
googleMaps.geocode({address: 'Sydney Opera House'}, function(cancel) {
cancelGeocode = cancel;
})
.then(json)
.then(function(response) {
// do something
});
// Meanwhile ...
if (weNoLongerNeedTheGeocode) {
cancelGeocode();
}
Cancelling the request would reject the promise.
@juliaogris I'd appreciate your opinion too.
from google-maps-services-js.
I ought to mention too that calling cancel() can only be a hint. It doesn't guarantee that the Promise will be rejected.
from google-maps-services-js.
Closing this now since I think we've addressed everything here with the current state of the library.
from google-maps-services-js.
Related Issues (20)
- PlacesAutocomplete call crashes if the optional location field is present but undefined HOT 2
- Address autocomplete ApiNotActivatedMapError HOT 1
- StreetViewService.getPanorama implementation HOT 2
- Cross-site Request Forgery (CSRF) issue with Axios, replace with fetch? HOT 7
- Add new Pollen APIs HOT 1
- Google RouteMatrix needed. HOT 2
- Dependency url-signature using a version of crypto-js with critical vulnerability HOT 6
- New APIs: Address Validation, Datasets, Places, Routes HOT 4
- Autocomplete prediction type fields should be optional HOT 1
- Rename primary branch to main
- reviews_sort & reviews_no_translations fields are not included in place deatils params HOT 2
- "Place Details (New)" API calls HOT 4
- Directions: Missing type "google.maps.DirectionsStatus" in "google.maps.DirectionsResult" OS:W11 Pro HOT 1
- Cannot find module 'core-js/modules/es.string.replace.js' HOT 5
- Add support for Address Descriptors to Geocoding
- Cross-Origin-Resource-Policy missing from response header of khms0.googleapis.com and khms1.googleapis.com HOT 1
- Error: Cannot find module 'core-js/modules/es.string.replace.js' HOT 10
- Places.placeAutocomplete can't filter by country HOT 1
- 127.0.0.1:22259/main/0/storage/emulated/11/Download/Takeout/Historial de ubicaciones (Rutas)/Timeline Edits.GeoJSON.gpx.html
- Error: Type '"origin" | undefined' is not assignable to type '"origin"' during Build. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-maps-services-js.