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.
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;
};
Return only the document which was updated and what change was performed on it
I'd like to know which action was performed on which document instead of doing complicated loops to detected the change
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too