observable1 = constructorZone1.run(() => {
   return Rx.Observable.range(0, 3)
       .map(function(x: any) {
         return Rx.Observable.range(x, 3);
       })
       .switch ();
 });
Example #2
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.forkJoin(
       Rx.Observable.range(1, 2), Rx.Observable.from([4, 5]), function(x, y) {
         expect(Zone.current.name).toEqual(constructorZone1.name);
         return x + y;
       });
 });
Example #3
0
 it('should count a range().take(1) source observable', (done: MochaDone) => {
   Rx.Observable.range(1, 10).take(1).count().subscribe(
     (value: number) => {
       expect(value).to.equal(1);
     }, (x) => {
       done(new Error('should not be called'));
     }, () => {
       done();
     });
 });
 .retryWhen((attempts:any) => {
     return Observable
         .range(1, 3)
         .zip(attempts, (i) => { 
             return i; 
         })
         .flatMap( (i) => {
             console.log("Unable to fetch...delay retry by " + i + " second(s)")
             return Observable.timer(i * 1000);
         })
 })
Example #5
0
  it('should subscribe to observables that are an instanceof Rx.Observable', (done) => {
    const expected = [1, 2, 3];
    const result = Rx.Observable.range(1, 3);

    const subscriber = new OuterSubscriber<number, number>(x => {
      expect(expected.shift()).to.be.equal(x);
    }, () => {
      done(new Error('should not be called'));
    }, () => {
      expect(expected).to.be.empty;
      done();
    });

    subscribeToResult(subscriber, result);
  });
Example #6
0
  constructor() {
    this.raw = [];

    this.numberStream = Rx.Observable.range(0,10);

    this.numberStream
      .subscribe(n => this.raw.push(n));

    this.numberStream
      .filter(n => n % 3 === 0)
      .map(n => n * 3)
      .toArray()
      .subscribe(numbers => this.numbers = numbers);

    this.numberStream
      .scan((sum: number, n: number) => sum + n)
      .subscribe((total: number) => this.total = total);


  }
Example #7
0
    // notify completion of observable.
    constructor() {

        var d1 = Observable.throw(new Error("error"));
        d1.subscribe(
            x => console.log(x),
            err => console.error(err),
            () => console.log("completed")
        );

        var d2 = Observable.range(1,10);
        d2.subscribe(
            x => console.log(x),
            err => console.error(err),
            () => console.log("completed")
        );

        // // own counter
        // var counter = 0;
        // var d3 = Observable
        //     .interval(1000)
        //     .flatMap(x => counter < 10 ? Observable.of(counter++) : Observable.throw("error"));
        // d3.subscribe(
        //     x => console.log(x),
        //     err => console.error(err),
        //     () => console.log("completed")
        // );

        var c = 0;
        var d4 = Observable
            .interval(1000)
            .take(10)
            .map(x => c++);
        d4.subscribe(
            x => console.log(x),
            err => console.error(err),
            () => console.log("completed")
        );
                
    }
            let generateRequests = (numberOfRequests: number) => {
                let requestStream = Observable
                    .range(startingPage + 1, numberOfRequests - 1)
                    .flatMap(pageNumber => {
                        return this.getPageRequest(pageNumber);
                    })

                requestStream.subscribe(
                    // On Value
                    (benchData: IBenchData) => {
                        results.next(benchData.transactions)
                    },
                    // On Error
                    (error: any) => {
                        console.log("Unable to execute request for additional remote resources")
                        results.error(error)
                    },
                    // On Complete
                    () => {
                        results.complete()
                    })
            }
Example #9
0
    constructor3() {
        console.log(new Observable());
        
        var d1 = Observable.empty();
        d1.subscribe(x => console.log(x));

        var d2 = Observable.range(1, 5);
        d2.subscribe(x => console.log(x));

        var d3 = Observable.fromArray([1,2,3]);
        d3.subscribe(x => console.log(x));

        var d4 = Observable.of(1);
        d4.subscribe(x => console.log(x));

        var d5 = Observable.of(1,2,3);
        d5.subscribe(x => console.log(x));

        var d6 = Observable.of([1,2,3]);
        d6.subscribe(x => console.log(x));
                
    }
 observable2 = constructorZone2.run(() => {
   return Rx.Observable.range(3, 4);
 });
Example #11
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.range(1, 3, Rx.Scheduler.asap);
 });
Example #12
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.range(1, 3);
 });
    constructor() {
        // Test various forms of Observable.
        console.log("fromArray [1,2,3]");
        var observable = Observable.fromArray([1, 2, 3])
            .subscribe(x => console.log(x));

        console.log("of [1,2,3]");
        observable = Observable.of([1,2,3])
            .subscribe(x => console.log(x));

        console.log("of 1,2,3");
        observable = Observable.of(1,2,3)
            .subscribe(x => console.log(x));

        console.log("empty");
        observable = Observable.empty()
            .subscribe(x => console.log(x));

        console.log("range 1,5");
        observable = Observable.range(1,5)
            .subscribe(x => console.log(x));

        console.log("completion function");
        observable = Observable.of(1)
            .subscribe(
                x => console.log(x),
                err => console.error(err),
                () => console.log("completed")
            );


        // console.log("interval 1000");
        // var interval = Observable.interval(10000)
        //     .flatMap(x => {
        //         // call server
        //         return Observable.of([1,2,3]);
        //     })
        //     .subscribe(x => console.log(x));

        // Simulating error.
        console.log("error handling");
        var errObs = Observable
            .throw(new Error("ahh!"))
            .subscribe(
                x => console.log(x), // success
                err => console.error(err) // error
            );

        // simulate a call which fails twice then succeeds.
        console.log("error handling with retry");
        var counter = 0;
        var ajaxCall = Observable.of('url')
            .flatMap(() => {
                if(++counter < 2)
                    return Observable.throw(new Error("ahh!"));

                return Observable.of([1,2,3]);
            })
            .retry(3)
            .subscribe(x => console.log(x), err => console.error(err));

        console.log("error handling with catch");
        var catchObs = Observable
            .throw(new Error("ahh!"))
            .catch(err => {
                return Observable.of([1,2,3]);
            })
            .subscribe(x => console.log(x));

        console.log("timeout");
        var timeout = Observable
            .of([1,2,3])
            .delay(5000)
            .timeout(100)
            .subscribe(x => console.log(x), err => console.error(err));

        // join two observables. Returns an array of the results
        // [o1.results, o2.results] after both complete. Map to something nicer.
        console.log("forkJoin");
        var o1 = Observable.of({
            userId: 1,
            username: 'something'
        }).delay(2000);
        var o2 = Observable.of([1,2,3]).delay(1500);
        Observable
            .forkJoin(o1,o2)
            .map(data => {
                {
                    return {
                        user: data[0],
                        stream: data[1]
                    };
                }
            })
            .subscribe(x => console.log(x));
    }
Example #14
0
console.log('test-rx.ts running...');

import { Observable } from 'rxjs/Rx';

Observable.range(1, 5).subscribe(value => console.log(value));
//maping thats i was looking for few days ago exact example wow!!

import { Observable } from 'rxjs/Rx';


var createing = Observable.range(1, 5);

//here data willl come into argum,ents
createing.map(function(data){
    return data * 2; //modifying
}).subscribe(function(data){
    console.log(data)
}, function(err){
    console.log(err)
}, function(){
    console.log('complete')
})
import { Observable } from 'rxjs/Rx';

Observable.range(1,10).filter(function(data){
    return data % 2 == 0; 
}).subscribe(function(data){
    console.log(data)
}, function(err){
    console.log(err)
}, function(){
    console.log('completed')
})
import { Observable } from 'rxjs/Rx';

Observable.range(1,10).reduce(function(accomulated : number, nextnumber : number){
    return accomulated + nextnumber
}).subscribe(function(data){
    console.log(data)
}, function(err){
    console.log(err)
}, function(){
    console.log('complete')
})
Example #18
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.forkJoin(Rx.Observable.range(1, 2), Rx.Observable.from([4, 5]));
 });
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.range(0, 3).switchMapTo('a');
 });
 return Rx.Observable.range(0, 3).switchMap(function(x: any) {
   return Rx.Observable.range(x, 3);
 });
 .map(function(x: any) {
   return Rx.Observable.range(x, 3);
 })
 .concatMap(_ => Rx.Observable.range(0, nbPage))
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.range(1, 3).count((i: number) => {
     expect(Zone.current.name).toEqual(constructorZone1.name);
     return i % 2 === 0;
   });
 });