asObservable - richardszalay/raix GitHub Wiki
ο»ΏHides the source sequence so it cannot be cast back to itβs concrete implementation. Often used with Subjects to avoid the consumer being able to call on*() on them.
function asObservable() : IObservable.<T>Useful for Subjects and custom implementations of IObservable, where you would not want calling code casting the sequence back to the original implementation
The returned sequence completes if the source sequence completes
The returned sequence errors if the source sequence errors or if func throws an error
xs ββoβββββoβββββ/
β β β
zs ββoβββββoβββββ/
xs ββoβββββoβββββx
β β β
zs ββoβββββoβββββxIObservable.<T>
var subject : Subject = new Subject();
// source cannot be cast back to Subject
var source : IObservable = subject.asObservable();
source.subscribe(
function(x:int) : void { trace(x); },
function() : void { trace("Completed"); }
);
subject.onNext(1);
subject.onNext(2);
subject.onNext(3);
subject.onCompleted();
// Trace output is:
// 1
// 2
// 3
// Completed