December 2015
Intermediate to advanced
144 pages
3h 37m
English
There are several ways to create Observables, the create operator being the most obvious one. The create operator in the Rx.Observable object takes a callback that accepts an Observer as a parameter. That function defines how the Observable will emit values. Here’s how we create a simple Observable:
| | var observable = Rx.Observable.create(function(observer) { |
| | observer.onNext('Simon'); |
| | observer.onNext('Jen'); |
| | observer.onNext('Sergi'); |
| | observer.onCompleted(); // We are done |
| | }); |
When we subscribe to this Observable, it emits three strings by calling the onNext method on its listeners. It then calls onCompleted to signal that the sequence is finished. But how exactly do we subscribe to an Observable? We ...
Read now
Unlock full access