Skip to content
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

Is it possible to use promises instead of event listeners #47

Closed
uslperera opened this issue Nov 7, 2018 · 2 comments
Closed

Is it possible to use promises instead of event listeners #47

uslperera opened this issue Nov 7, 2018 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@uslperera
Copy link

According to this example code, you can perform the geo location based search.

const onKeyEnteredRegistration = geoQuery.on('key_entered', function(key, document, distance) {
  console.log(key + ' entered query at ' + document.coordinates.latitude + ',' + document.coordinates.longitude + ' (' + distance + ' km from center)');
});

Is it possible to use promises to get the same result. If so could you please give an example?

@MichaelSolati
Copy link
Owner

Unfortunately no, the library is designed to listen for changes in the database as well as your query and fire off new results as individual items as they come in. (Just how geofire does) In effect the query would never have a resolution (which a Promise would need) as it is always listening and updating.

You could instead use the ready listener to kill the subscription to your query when it triggers for now. However v3 will be more like the regular Firestore library where there will be promises and listeners.

@MichaelSolati MichaelSolati added the enhancement New feature or request label Nov 8, 2018
@MichaelSolati MichaelSolati added this to the v3.0.0 milestone Nov 8, 2018
@MichaelSolati MichaelSolati self-assigned this Dec 14, 2018
@MichaelSolati
Copy link
Owner

@uslperera version 3.0.0 has a get() function which returns a promise. While v3 is massively different, the spittin-hot-geofirestore repo shows an example of how to use it promises with the library!

Here you go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants