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

Vuexfire: Add includeMetadataChanges option to snapshot handling #883

Open
flashfabrixx opened this issue Sep 10, 2020 · 1 comment
Open

Vuexfire: Add includeMetadataChanges option to snapshot handling #883

flashfabrixx opened this issue Sep 10, 2020 · 1 comment

Comments

@flashfabrixx
Copy link

@flashfabrixx flashfabrixx commented Sep 10, 2020

What problem is this solving

Related to firebase/firebase-js-sdk#3661 this feature will enable listening to changes of the metadata to e.g. check for documents, which aren't synced with the server yet.

At this time it's required to reload the data manually as the Vuex store is not notified about the changes for the metadata of the given query.

Proposed solution

Extend FirestoreOptions with parameter IncludeMetadataChanges and pass parameter to native Firebase handling.

Example code

// ...
// Get `id`, `hasPendingWrites` and `fromCache` from snapshot data
const serialize = snapshot => {
      return Object.defineProperties(snapshot.data(), {
        id: {
          value: snapshot.id,
        },
        hasPendingWrites: {
          value: snapshot.metadata.hasPendingWrites,
        },
        fromCache: {
          value: snapshot.metadata.fromCache,
        },
      });
    };

    // Get ref with custom query
    const ref = db
      .collection("jobs")
      .where("userId", "==", user.uid)
      .limit(20)
      .orderBy("due");

     // Setup binding including metadata changes
     bindFirestoreRef("list", ref, {
      serialize: serialize,
      reset: false,
      includeMetadataChanges: true <-- NEW
    })

Describe alternatives you've considered

I've tried to find other native methods or workarounds but did not find a solution yet.

@flashfabrixx flashfabrixx changed the title Vuexfire: Add `includeMetadataChanges` option to snapshot handling Vuexfire: Add includeMetadataChanges option to snapshot handling Sep 10, 2020
@posva
Copy link
Member

@posva posva commented Sep 10, 2020

Yeah, we should definitely allow a way of passing https://firebase.google.com/docs/reference/js/firebase.firestore.SnapshotListenOptions, probably as a whole option named snapshotListenOptions even though I would really like to do it like you suggested: merging the types. I don't think we will have any overlap in naming properties but I think the other version will compress better if more options are added by the Firebase team later on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.