-
Notifications
You must be signed in to change notification settings - Fork 68
feat: implement updated and simplified API #1068
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
cd52238
feat!: implement updated and simplified API
usefulthink 9cb6216
chore: update bundlewatch workflow
usefulthink f377392
chore: update typedoc config
usefulthink 249d1e9
chore: revert change in codeql.yml workflow
usefulthink e903388
chore: reorganize npm scripts
usefulthink 8ada50e
chore: consistent license comments
usefulthink f691bb1
refactor: reformat messages, remove dev-switch for dev-only messages
usefulthink e345b83
chore: update build-config
usefulthink 859f634
fix: add extra implementation signature
usefulthink 17b6b04
fix: add full stub implementation of the 1.x interface
usefulthink ba82687
docs: add migration instructions
usefulthink a8f05bb
fix: corrected exported types and jsdoc
usefulthink 524d031
docs: update MIGRATION.md
usefulthink d316777
refactor: rename "bootstrap" to "installImportLibrary"
usefulthink bbf18ab
chore: copyright year
usefulthink 47a6fd3
chore: copyright year
usefulthink 37b7f8e
chore: license-header first
usefulthink 7429dde
fix: libraries and mapIds always specified as string[]
usefulthink c86821d
fix: make Loader stub fail hard
usefulthink 7064109
fix: add docs for bootstrap function
usefulthink 98e5019
fix: remove cooperative loading, rework dev-messages
usefulthink 323800f
docs: update readme
usefulthink 26b24f5
docs: update readme
usefulthink 19d2f68
docs: update readme
usefulthink ad7aa17
fix: eslint issues
usefulthink 43c8105
chore: remove generated documentation
usefulthink 4372b4a
chore: remove builds for direct browser-usage
usefulthink 9570c86
fix: move bootsrapping to setOptions, improve error-messages
usefulthink 432a9a8
docs: typos in migration.md
usefulthink 2637933
chore: remove example
usefulthink 4261075
docs: update readme
usefulthink 9b31130
docs: update readme
usefulthink 92049aa
chore: npm update
usefulthink c11fd94
docs: update readme
usefulthink 8d15fc3
docs: update readme
usefulthink 4666330
docs: update readme
usefulthink 996bdcd
chore: docs, formatting, linting, and minor changes
usefulthink a4687ac
Merge remote-tracking branch 'upstream/main' into v2.0-dev
usefulthink fa2a228
chore: fix package-lock.json
usefulthink fc9e517
chore: update bundlewatch config
usefulthink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"files": [ | ||
{ | ||
"path": "dist/index.*.js" | ||
"path": "dist/index*.js" | ||
} | ||
], | ||
"ci": { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/bootstrap.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
bracketSpacing: false, | ||
singleQuote: true, | ||
trailingComma: "all", | ||
arrowParens: "avoid", | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# Migration from v1.x to v2.x | ||
|
||
This guide provides instructions for migrating from version 1.x of | ||
`@googlemaps/js-api-loader` to version 2.x. | ||
|
||
## Core Concepts | ||
|
||
The primary change in v2.x is the move from a class-based (`Loader`) to a | ||
functional approach. This simplifies the API and aligns it with | ||
[the recommended way](https://developers.google.com/maps/documentation/javascript/load-maps-js-api) | ||
to load the Google Maps JavaScript API. | ||
|
||
- **v1.x:** You would create an instance of the `Loader` class with your | ||
configuration and then call methods like `load()` or `importLibrary()` on | ||
that instance. | ||
- **v2.x:** You now use two standalone functions: `setOptions()` to | ||
configure the API loader and `importLibrary()` to load specific libraries. | ||
|
||
Generally, the Loader constructor can be replaced with a call to `setOptions()`, | ||
and the different methods used to actually load the API are all replaced | ||
with calls to `importLibrary()`. | ||
|
||
## Key Changes | ||
|
||
| Feature | v1.x (`Loader` class) | v2.x (functions) | | ||
| :--------------------- | :----------------------------------- | :-------------------------------------- | | ||
| **Initialization** | `new Loader({ apiKey: '...', ... })` | `setOptions({ key: '...', ... })` | | ||
| **Loading Libraries** | `loader.importLibrary('maps')` | `importLibrary('maps')` | | ||
| **Legacy Loading** | `loader.load()` | Removed. Use `importLibrary()` instead. | | ||
| **API Key Parameters** | `apiKey` | `key` | | ||
| | `version` | `v` | | ||
|
||
## Typical Use Cases Compared | ||
|
||
### v1.x | ||
|
||
The most common use case of the 1.x versions was loading a predefined set of | ||
libraries explicitly, and then using the global `google.maps` namespace. | ||
|
||
```javascript | ||
import { Loader } from "@googlemaps/js-api-loader"; | ||
|
||
const loader = new Loader({ | ||
apiKey: "YOUR_API_KEY", | ||
version: "weekly", | ||
libraries: ["maps", "places"], | ||
}); | ||
|
||
// a) using load() with promises | ||
loader.load().then(() => initMap()); | ||
|
||
// b) using load() with async/await: | ||
await loader.load(); | ||
initMap(); | ||
|
||
// c) using callback | ||
loader.loadCallback(() => { | ||
initMap(); | ||
}); | ||
|
||
function initMap() { | ||
// use the global google.maps namespace once loading is complete | ||
const map = new google.maps.Map(document.getElementById("map"), { | ||
center: { lat: -34.397, lng: 150.644 }, | ||
zoom: 8, | ||
}); | ||
} | ||
``` | ||
|
||
### v2.x | ||
|
||
The typical use case from versions 2.0 onwards is to use `importLibrary` to get | ||
access to the classes and features needed from the Maps JavaScript API. | ||
|
||
```javascript | ||
import { setOptions, importLibrary } from "@googlemaps/js-api-loader"; | ||
|
||
setOptions({ | ||
key: "YOUR_API_KEY", | ||
v: "weekly", | ||
}); | ||
|
||
try { | ||
const { Map } = await importLibrary("maps"); | ||
// Use the maps library | ||
const map = new Map(document.getElementById("map"), { | ||
center: { lat: -34.397, lng: 150.644 }, | ||
zoom: 8, | ||
}); | ||
} catch (e) { | ||
// do something | ||
} | ||
``` | ||
|
||
However, all the examples from the 1.x version can also be written based | ||
on the 2.x version, since – besides returning the library object – the | ||
`importLibrary()` function also populates the global `google.maps` namespace. | ||
|
||
<details> | ||
<summary>Imitating the 1.x API</summary> | ||
|
||
```javascript | ||
import { setOptions, importLibrary } from "@googlemaps/js-api-loader"; | ||
|
||
setOptions({ | ||
key: "YOUR_API_KEY", | ||
v: "weekly", | ||
|
||
// Libraries can still be specified in `setOptions`. This makes sure that | ||
// all libraries are available when the importLibrary promise is resolved. | ||
libraries: ["maps", "places"], | ||
}); | ||
|
||
// The examples from above, rewritten with v2.0: | ||
// | ||
// a) using promises (note: which library is imported in these cases makes | ||
// little difference: the libraries were specified in `setOptions` and | ||
// we're not using the returned value) | ||
importLibrary("core").then(() => initMap()); | ||
|
||
// b) using load() with async/await: | ||
await importLibrary("core"); | ||
initMap(); | ||
|
||
// c) using a callback – this is identical to a) | ||
|
||
function initMap() { | ||
// Use the global google.maps namespace once loading is complete | ||
const map = new google.maps.Map(document.getElementById("map"), { | ||
center: { lat: -34.397, lng: 150.644 }, | ||
zoom: 8, | ||
}); | ||
} | ||
``` | ||
usefulthink marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
</details> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.