step-up-labs / firebase-database-dotnet

C# library for Firebase Realtime Database.
MIT License
671 stars 170 forks source link

Duplicate data using Realtime Streaming #198

Closed ghost closed 4 years ago

ghost commented 5 years ago

Awesome work @bezysoftware

I'm trying to feed a simple ItemsControl list with real time data using AsObservible. It's updating correctly when changing data in Firebase but all objects in my collection is duplicating randomly over time.

First all objects loads but after like 30 seconds the same objects adds to the list.

Is this the wrong approach or am I missing something?

public MainWindow()
{
InitializeComponent();
var childUsers = client.Child("Users");
var observable = childUsers.AsObservable<User>();
Users.ItemsSource = observable.ObserveOnDispatcher().AsObservableCollection();
}

Cheers!

bezysoftware commented 5 years ago

I am not sure what the AsObservableCollection extension method does, but I would assume that's what causes the duplication. Essentially you can receive the same User object multiple times when you subscribe (it can change on server, connection can be restarted etc). In that case you need to manually handle the object being received again - either replacing the old one, or updating it.

fabricciotc commented 5 years ago

Just use Clear() in ur datagrid before you add a new item o modify

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing the issue due to inactivity. Feel free to re-open