question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.AsObservable() .Subscribe always returns the first post instead of changed,updated post.

See original GitHub issue
.Child("Posts")
.AsObservable()
.Subscribe(d => Console.WriteLine(d.Key));

Expecting key of updated post but instead receive the first post as listed on Realtime Database. Anyone else having this behaviour?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
TennisDrumcommented, Mar 18, 2019

I have several subscriptions working in an app I’m working on. An example of one is shown below. One thing I noticed that’s different with yours is in the .AsObservable() line, there’s no object class designated (see my example below - “Event” is an object Class). I’m not an expert here - just know what I’ve done to get this to work. Also, in my example “returnedEvents” is an IDisposable. _returnedEvents is an ObservableCollection.

returnedEvents = App.firebase
            .Child("Events")
            .AsObservable<Event>()
            .Subscribe(eventReceived =>
            {

                // check to see what type of FirebaseEvent was detected by the subscription
                if (eventReceived.EventType == Firebase.Database.Streaming.FirebaseEventType.Delete)
                    // record deleted - remove from ObservableCollection
                    _returnedEvents.Remove(eventReceived.Object);

                // record was added or updated
                if (eventReceived.EventType == Firebase.Database.Streaming.FirebaseEventType.InsertOrUpdate)
                {
                    // see if the inserted/updated object is already in our ObservableCollection
                    var found = _returnedEvents.FirstOrDefault(i => i.Key == eventReceived.Key);

                    if (found == null)
                    {
                        //  is NOT in the observableCollection - add it
                        _returnedEvents.Add(eventReceived.Object);
                    }

                    // nothing to do if eventReceived is already in our ObservableCollection - because
                    // of INotifyPropertyChanged, the update will happen automatically
                }

            });
0reactions
stale[bot]commented, Oct 9, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any pitfall return subject.asObservable() right after ...
No, observable will always have the value which was passed in next() . Having said that, whenever a subscription is done on the...
Read more >
Best practices for using asObservable() in a class : r/Angular2
I got into a discussion with a coworker, because I always return my Subject asObservable, while he says that the return type is...
Read more >
Al-Kathiri Khalid | Just another WordPress.com site
First thing first, head over to LCD WIKI and grab a screen of your liking, in ,my case I went with: Raspberry Pi...
Read more >
Here - Agents Lab - University of Nottingham
First, even though a system is seen as set <strong>of</strong>interacting components, these components are rather statically connected with ...
Read more >
Web Development With Angular And Bootstrap
In our reworking of the original CarHorsepowerComponent class, we've lightened up our component template by moving the logic into a function within the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found