The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Introducing the Observable

Introducing the Observable

11:59
In this lesson we will get introduced to the **Observable** type. An Observable is a *collection that arrives over time*. Observables can be used to model events, asynchronous requests, and animations. Observables can also be transformed, combined, and consumed using the Array methods we learned in the previous lessons. We can write powerful and expressive asynchronous programs using the few simple methods we've learned so far.
Watch this lesson now
Avatar
egghead.io

In this lesson we will get introduced to the Observable type. An Observable is a collection that arrives over time. Observables can be used to model events, asynchronous requests, and animations. Observables can also be transformed, combined, and consumed using the Array methods we learned in the previous lessons. We can write powerful and expressive asynchronous programs using the few simple methods we've learned so far.

Avatar
Jay

The onCompleted callback never gets called. I was expecting that to be called after subscription.dispose(). Wouldn't that need to happen for the array and observable code to be equivalent?

Avatar
Joel

You are disposing of the subscription to the Observable prior to the Observable's completion. In this case (click watching) the Observable is "infinite" and will never complete.

In reply to Jay
Avatar
Dean

Dig your style, very easy to understand. But I do have one question or perhaps someone else can answer -- Can you show a practical example of when using Oberservable is useful. I see that it is asynchronous, but again - how would you use this in a real world application, on front javascript usage? I don't see how this is useful outside of just using traditional event listerns. Please let me know.

In reply to egghead.io
Avatar
Jafar

This is coming very soon. We'll show you how to compose event listeners, Async requests, and animations together to solve problems. We're building to that so when we get there you'll undertstand.

In reply to Dean
Avatar
labeeb

I commented out subscription.dispose(); still why onCompeleted is not called?

In reply to Joel
Avatar
Jafar

A good example would be a autocomplete box. An auto complete box requires you to combine together events, asynchronous requests, and in some cases animations. As Observables can model all of these things, you can seamlessly combine these different asynchronous data sources together declaratively. Expect more on this in future videos.

In reply to Dean
Avatar
Zach

Is there something I am missing? I am using node, I am able to get it viewing on my localhost but not able to get a simple alert working.

I require rx in my js file , i put that js script tag in my html

Avatar
Alesei

which version of Rx.js you are requiring?

In reply to Zach
Avatar
kisanbhat

rx.all.js:7631 Uncaught TypeError: Cannot read property 'addListener' of null

I am getting the above mentioned error and in HTML code I have added rx.all.js (v4.1.0) . Any idea why I am getting this error?

Avatar

This course has totally changed the way I think about handling events, thank you so much for such a clear explanation of the technique.

Avatar
mobility-team

I guess it's important to notice that Array.prototype.forEach is not asynchronous, but Observable.prototype.forEach is. Or am I wrong?

Avatar
Jafar

Technically it's possible for an observable to fire either synchronously or asynchronously. Overall you're right.

In reply to mobility-team
Avatar
Daniel

With the newer version of rxjs => https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.0.0/Rx.min.js, it calls the onError(error) right away, even before I click on the button - it triggers on page load. Will you update your tutorial or provide an answer on why is this happening? Thank you.

Avatar
Jafar

I think you will have to include a code example. There are several cosmetic differences between the version of RX used in this course and the new version of RX. The code may not work exactly as is. I will need to see your port.

In reply to Daniel
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?