Closed otymartin closed 2 years ago
CombineFirebase is exactly for this. Purpose of combineFirebase is to give firebase listener api lifecycle of a publisher, which should be the default lifecycle for any api in new Combine Framework paradigm. Default lifecycle of a publisher is, data is being listened after at-least one subscriber being subscribed to publisher, this is done via sink and assign api. Both sink and assign api in turn return Cancelable, which you can use to stop listener by using [cancel()](https://developer.apple.com/documentation/combine/cancellable/cancel()) method of cancellable. Basically all the api of combineFirebase remove listeners on cancel method invocation. You can dig in source here, to understand its implementation, this is exactly what firebase is recommending in there docs. Hope that answer your concern. 🙌
@kshivang Ahh very informative piece. I always store in my cancelbag because compiler demands it, didn't care to understand it until now.
I saw cancel()
method in your code but couldn't figure out why it wasnt called but I see it in the Cancellable
protocol.
Thanks very educational explanation.
@kshivang
According to the Firebase docs
So I'm curious how is it that
CombineFirebase
handles this as I can't find any code referencing the removal or detachment of these listeners. I'm concerned with bandwidth usage which can get expensive.Is
CombineFirebase
doing this automatically somehow or are we responsible for it?