MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
505 stars 58 forks source link

Question about query in updateCriteria #35

Closed 19th closed 6 years ago

19th commented 6 years ago

Hello! Sorry for basic question, but can't get my code to work.

Problem: I have two ways of calling updateCriteria method, but only first one triggers updates:

  1. Updating center and distance

    onMapChange(center, radius) {
        this.geoQuery.updateCriteria({
            center: new firebase.firestore.GeoPoint(...center),
            radius: radius
        });
    }
  2. Updating query

    updateQuery() {
        this.geoQuery.updateCriteria({
            query: (ref) => ref.where('d.type', '==', this.state.type);
        });
    }

After calling onMapChange() or updateQuery() I expect documents to be filtered out, but in case of updateQuery() nothing really happens. I tried passing literally any query and by requesting this.geoQuery._query.tosString() query always changed, but documents are not changed.

Am I doing this right?

MichaelSolati commented 6 years ago

Are you saying that the on listener is returning docs that shouldn't be returned? (I'm not 100% clear on what you're doing and what is expected... )

19th commented 6 years ago

@MichaelSolati, yes. After changing query in updateCriteria nothing happens. key_exited or key_enterd isn't fired.

MichaelSolati commented 6 years ago

So nothing should/could/would happen. So key_exited CANNOT be fired because we don't know what your query is. We can't see your query function, so we can't do a check/validate if the old enteries are still in the query (except for doing a basic distance check).

key_entered shouldn't fire either, because if your location is the same all of the old docs that had fired that matched your query are still valid, so geofirestore won't fire an event.

If you're changing the query function it would be best to treat it as a new query and clear out your store of previous results.

19th commented 6 years ago

@MichaelSolati then it doesn't make sense to have query as argument in updateCriteria since it can't be changed.

MichaelSolati commented 6 years ago

It'll just effect future changes to the entire query. I'm not saying it makes perfect sense, but it definitely requires a refactor. (Which there are a slew of changes I have in mind which I want to make in the near future)

19th commented 6 years ago

Thanks for answer! This is very nice library covering Firestore`s flaw with missing native GeoQuery. Nice job!