geofire-js
geofire-js copied to clipboard
wrap off(firebaseQuery, 'value', valueUnsubscribe) in setTimeout-0
Description
In some cases (especially when frequently subscribing and unsubscribing geo queries) there was an error:
Uncaught ReferenceError: Cannot access 'valueUnsubscribe' before initialization at GeoQuery.ts:485:37
It seems that in those cases the callback provided to onValue was called synchronously before returning valueUnsubscribe from the function call. Therefore valueUnsubscribe was not yet fully defined (Temporal Dead Zone ?)
I have just looked into the docs for onValue: it returns an unsubscribe function. So my question is: Does this implementation:
off(firebaseQuery, 'value', valueUnsubscribe);
really unsubscribe correctly? Shouldn't it just be:
valueUnsubscribe();