geofirestore-js icon indicating copy to clipboard operation
geofirestore-js copied to clipboard

Unsubscribe from GeoQuery.onSnapshot on document deletion

Open Daeon97 opened this issue 1 year ago • 1 comments

Hello Michael 👋 I am having issues unsubscribing from a GeoQuery.onSnapshot in an onWrite Cloud Function.

At the topmost of the function body i have a variable listener let listener; Then i have two conditions that checks whether a document was just created or deleted if(!change.before.exists && change.after.exists){ /* checks if document was just created */ } and if(change.before.exists && !change.after.exists){ /* checks if document was just deleted */ }

Inside the first if block i assign ...onSnapshot(...) to listener listener = ...onSnapshot(...); Then inside the second if block i call listener() to unsubscribe from the GeoQuery.onSnapshot subscription made in the first if block as stated in your API docs, in other words, when a document is created the listener is assigned to ...onSnapshot(...). Subsequently when that same document is deleted, i try to unsubscribe from the previous onSnapshot subscription

The problem is i am getting an error

TypeError: listener is not a function

This Cloud Function is in such a way that the first if block will always get called before the second if block (obviously a document can get deleted only after it is created). I don't see what i seem to be doing wrong here. I need some help

I have also posted a more elaborate description of the issue i am facing on Stackoverflow here https://stackoverflow.com/questions/73803324/unsubscribe-from-geoquery-onsnapshot-on-document-deletion

Daeon97 avatar Sep 21 '22 14:09 Daeon97