f-miyu / Plugin.CloudFirestore

MIT License
121 stars 44 forks source link

How to unsubscribe a listener? #25

Open Thorastur opened 4 years ago

Thorastur commented 4 years ago

In Firebase documentation is like this:

FirestoreChangeListener listener = query.Listen(snapshot => { foreach (DocumentChange change in snapshot.Changes) { if (change.ChangeType.ToString() == "Added") { Console.WriteLine("New city: {0}", change.Document.Id); } else if (change.ChangeType.ToString() == "Modified") { Console.WriteLine("Modified city: {0}", change.Document.Id); } else if (change.ChangeType.ToString() == "Removed") { Console.WriteLine("Removed city: {0}", change.Document.Id); } } });

await listener.StopAsync();

But i don´t know how to do this with this pluguin!, help please

Thorastur commented 4 years ago

Ok, i found the solution:

        var listener = CrossCloudFirestore.Current.Instance
                       .GetCollection("yourcollection")
                       .GetDocument("yourdocument")
                       .AsObservable()
                       .Subscribe(document =>
                       {
                           var change = true;
                       });

        listener.Dispose();