This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
feat(controlled-search): expose search method in places.js #659
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.
Summary
Before this PR, in order to do a query programmatically, you had to use the JS api client with the
.initPlaces
method. This was problematic for multiple reasons, the first one being that this increased bundle size, and also meant learning about the response from the API which is a bit more complex than the pre-formattedsuggestion
objects that are exposed in the places.js library, and combining the two different format is error-prone.With this PR, the
search
method is now accessible at the instance level.Result
The shape of the search method is:
Important: the exposed
search
method uses the internal configuration of the places instance to apply its filter. The reason for that is that this.search
method is simply a wrapper around the search function generated by the createDataSource function, and this search function only accepts a query and a callback as parameters, and does not accept additional options to use for that query. Modifying that behaviour would imply a change in the interface which would be a breaking change, so I did not do that in that PR.If we think that this breaking change is worth it, we can work on it while preparing a
v2.0.0
of Places.Updated Example with
.search
method: