step-up-labs / firebase-database-dotnet

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

Observable cannot cast Expected #324

Open TomasGranda opened 2 months ago

TomasGranda commented 2 months ago

Hi, i'm trying to use the Observer this way:

var observable = GetFirebaseClient()
      .Child("rooms")
      .Child(playerID)
      .AsObservable<string[]>()
      .Subscribe(players =>
      {
        Debug.Log(players.Object);
      }, ex =>
      {
        Debug.LogError(ex);
      });

but the observer never runs the first callback.

When i use the observer this way:

var observable = GetFirebaseClient()
      .Child("rooms")
      .Child(playerID)
      .AsObservable<object>()
      .Subscribe(players =>
      {
        Debug.Log(players.Object);
      }, ex =>
      {
        Debug.LogError(ex);
      });

it works and print this: image

image

As expected. I don't know if this is a bug or i'm using the observer wrong.

Edit:

i fix it using this code:

GetFirebaseClient()
      .Child("rooms")
      .OrderByKey()
      .StartAt(playerID)
      .AsObservable<object>()
      .Subscribe(players =>
      {
        Debug.Log(players.Object);
      },
      ex => Debug.LogError(ex), () => Debug.Log("Completed"));

using OrderByKey and StartAt

TomasGranda commented 2 months ago

Apparently my issue is that i get 2 updates. 1 when i suscribe for nothing and 1 when i modify the node i'm observing. I don't know why i'm getting 2 updates but ok