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

feat(firestore): collection snapshots doc changes type #467

Open
1 of 9 tasks
jongbonga opened this issue Oct 17, 2023 · 0 comments
Open
1 of 9 tasks

feat(firestore): collection snapshots doc changes type #467

jongbonga opened this issue Oct 17, 2023 · 0 comments

Comments

@jongbonga
Copy link

Plugin(s)

  • Analytics
  • App
  • App Check
  • Authentication
  • Crashlytics
  • Cloud Firestore
  • Cloud Messaging
  • Performance
  • Remote Config

Current problem

Currently, the CollectionSnapshotListener returns all the doc changes, as it should, but there is no built-in way to determine what update was performed (added, modified, removed) like the JS SDK exposes here.

Preferred solution

Attach docChanges to the snapshots to view which action was performed on each documents

const addCollectionSnapshotListener = async () => {
  const callbackId = await FirebaseFirestore.addCollectionSnapshotListener(
    {
      reference: 'users',
      compositeFilter: {},
      queryConstraints: []
    },
    (event, error) => {
      if (error) {
        console.error(error);
      } else {
        event.snapshots.docChanges.forEach(change => {
          if (change.type === 'added') {
            console.log('New city: ', change.doc.data());
          }
          if (change.type === 'modified') {
            console.log('Modified city: ', change.doc.data());
          }
          if (change.type === 'removed') {
            console.log('Removed city: ', change.doc.data());
          }
        });
      }
    }
  );
  return callbackId;
};

Alternative options

Return only the document which was updated and what change was performed on it

Additional context

I'd like to know which action was performed on which document instead of doing complicated loops to detected the change

@robingenz robingenz added this to the v5.3.0 milestone Oct 17, 2023
@robingenz robingenz modified the milestones: v5.3.0, v5.4.0 Nov 28, 2023
@robingenz robingenz changed the title feat: Collection snapshots doc changes type feat(firestore): collection snapshots doc changes type Dec 14, 2023
@robingenz robingenz modified the milestones: v5.4.0, v5.5.0 Jan 23, 2024
@robingenz robingenz removed this from the v5.5.0 milestone Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants