constructor() {
   this.errorObservable = Observable.create((observer:Observer<any>) => {
     this.errorObserver = observer;
   }).share();
 }
    constructor() {
        const MAX_NUM_ARRAY = 25;
        const MS_LIMIT = 1000;
        const MS_INTERVAL_SOURCE = 10;
        const MS_INTERVAL_ARRAY = 1;
        
        console.clear();
        
        let i = 0;
        let timerSource = Observable.create((observer) =>{
        
            let idInterval = setInterval(() => {
                observer.next(i++);
                if(i >= MS_LIMIT) observer.complete();
            }, MS_INTERVAL_SOURCE);
            
            return () => {
                clearInterval(idInterval);
            };
        });
        
        let arrayStrem = Observable.create((observer) => {
           let myVet = Array.from(Array(MAX_NUM_ARRAY).keys());
           
            let idInterval = setInterval(() => {
                myVet[Math.floor(Math.random() * (MAX_NUM_ARRAY - 0)) + 0] = new Date().getMilliseconds();
                observer.next(myVet);
                if(i >= MS_LIMIT) observer.complete();
            }, MS_INTERVAL_ARRAY);
            
            return () => {
                clearInterval(idInterval);
            };      
        });
        
       let result = timerSource
            .map(x => parseInt(x))
            .filter(x=> x % 2 === 0)
            .reduce(function (acc, x, idx, source) {
                return acc + x;
            }, 1);
            
       let scanSteram = timerSource
            .map(x => parseInt(x))
            .filter(x=> x % 2 === 0)
            .scan((a,c) => a + c, 1);     
        
      this.bindStream = arrayStrem;
            
            
      arrayStrem.subscribe(
            () => {},
            err => console.log(err),
            () => console.log('onComplete of arrayStrem', new Date().getMilliseconds())
        );      

       scanSteram.subscribe(
            (x:number) => (this.currentSum = x),
            err => console.log(err),
            () => console.log('onComplete of scanStream', new Date().getMilliseconds())
        );
        
       timerSource.subscribe(
            (x:number) => (this.currentValue = x),
            err => console.log(err),
            () => console.log('onComplete of mapper', new Date().getMilliseconds())
        );

       result.subscribe(
            x => console.log(x),
            err => console.log(err),
            () => console.log('onComplete of reduce', new Date().getMilliseconds())
        );


    }
Example #3
0
 private subscribeToSaveResponse(result: Observable<Tamanhos>) {
     result.subscribe((res: Tamanhos) =>
         this.onSaveSuccess(res), (res: Response) => this.onSaveError());
 }
Example #4
0
 private handleError (error: Response) {
     console.error(error);
     return Observable.throw(error.json().error || 'Server Error');
 }
 // Uses Observable.forkJoin() to run multiple concurrent http.get() requests.
 // The entire operation will result in an error state if any single request fails.
 getBooksAndMovies() {
     return Observable.forkJoin(
     this.http.get('/app/books.json').map((res:Response) => res.json()),
     this.http.get('/app/movies.json').map((res:Response) => res.json())
     );
 }
Example #6
0
function detectTrends(quote$: rx.Observable<Quote>) : rx.Observable<Trend>  {
  return rx.Observable.empty<Trend>();
}
 private subscribeToSaveResponse(result: Observable<PersonelHotpersonel>) {
     result.subscribe((res: PersonelHotpersonel) =>
         this.onSaveSuccess(res), (res: Response) => this.onSaveError(res));
 }
Example #8
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.timer(10, 20);
 });
 .flatMap(s => {
     var url = "https://api.spotify.com/v1/search?type=artist&q=" + s;
     var promise = $.getJSON(url); // get the promise from getJSON
     return Observable.fromPromise(promise); // subscribe to the promise
 }); // flatMap flattens our Observable of Observables
Example #10
0
check() {
  return Observable.of(this.loggedIn);
  }