return observable.catch((err: any): any => {
   console.log(err);
   if (err.status === 400 || err.status === 401 || err.status === 422) {
     console.log("Notifying...");
     console.log(err.json());
     this.growlMessageService.notifyError(err.json());
     return Observable.empty();
   }
   else {
     console.log("Redirecting...");
     this.router.navigate(['/error-page']);
     return Observable.empty();
   }
 })
  createLesson(name, context){

    if(!name || !context){
      let empty_observable = Observable.empty();
      console.log("no name or no context");
      return empty_observable;
    }

    let lesson_json = {name: name, context: context};
    let lesson_str = JSON.stringify(lesson_json); 
    let headers = new Headers({'Content-Type': 'application/json'});
    let options = new RequestOptions({headers: headers})
    const network$ = this.http.post('http://cxense.webdemo.dac.co.jp:3000/test/lesson', lesson_json, options)
                        .cache(1);
/*
 ここで、network$は、serviceとcomponentの二ヶ所でsubscribeしているので、
 二回PostRequesstが呼ばれてしまう。
 cache オペレータを用いると、二度の無駄なPostRequestは実行されず、一回になる。
 ただし、Subscribe後に実行されるnextとcompleteは両方ともよばれる。
*/ 
    network$.subscribe(
      () =>{console.log("create lesson succeed : service")},
      (error) => {console.log("create lesson error" + error)},
      ()=>{console.log("create lesson complete: service")}
    )
    return network$;
  }
Example #3
0
    private handleResponse( res: Response ) {
        console.log( "handleResponse: " );
        // console.log( "handleResponse: " + res.toString() );
        var json = res.json();

        // console.log( "jsonResponse: " + JSON.stringify( json ) );

        // console.log( "Checking errors" );
        if ( json.actionErrors && Object.keys( json.actionErrors ).length > 0 ) {
            console.log( "has Errors!!!" );
            throw res;
        }

        // console.log( "Checking login" );
        if ( json.responseCode && json.responseCode == "login" ) {
            console.log( "Needs login!!!" );
            this.router.navigate( ['/login'] );

            return Observable.empty();
        }

        // console.log( "All OK" );

        return res;
    }
 .map((params: Params): Observable<PypiPackage[]> => {
   const queryPackages = params['packages'];
   if (queryPackages) {
     return this._packageService.getPackages(queryPackages);
   } else {
     return Observable.empty();
   }
 })
 .catch((err: any): any => {
     if (err.status === 400 || err.status === 422) {
         return Observable.throw(err);
     } else {
         //this.errorService.notifyError(err);
         return Observable.empty();
     }
 })
Example #6
0
 .concatMap(obj =>
   obj.stats.isDirectory()
     ? (
       dirBlacklist.has(obj.name)
         ? Observable.empty()
         : walkHelper(obj.path, dirBlacklist)
     )
     : Observable.of(obj)
Example #7
0
 return observable.catch((err, source) => {
   if (err.status  === 401 && !_.endsWith(err.url, '/login')) {
       this._router.navigate(['login']);
       return Observable.empty(null);
     } else {
       return Observable.throw(err);
   }
 });
 }).catch(err => {
   if (err.status == 401) { // Unauthorized i.e. not logged in
     console.info('No valid token, redirecting to login', err.json());
   } else {
     console.error('resume error', err);
   }
   this.router.navigate(['login']);
   return Observable.empty();
 }).finally(resolveDone);
Example #9
0
  it('should mirror source if durations are Observable.empty()', () => {
    const e1 =   hot('abcdefabcdefabcdefabcdefa|');
    const e1subs =   '^                        !';
    const e2 =  Rx.Observable.empty();
    const expected = 'abcdefabcdefabcdefabcdefa|';

    const result = e1.audit(() => e2);

    expectObservable(result).toBe(expected);
    expectSubscriptions(e1.subscriptions).toBe(e1subs);
  });
  deleteLesson(name_arr : string[]){

    if(!Array.isArray(name_arr) || name_arr.length == 0){
      let empty_observable = Observable.empty();
      console.log("no item to delete");
      return empty_observable;
    }


    let delete_lesson_str = JSON.stringify(name_arr); 
    let headers = new Headers({'Content-Type': 'application/json'});
    let options = new RequestOptions({headers: headers});
    let req_url = "http://cxense.webdemo.dac.co.jp:3000/test/lesson?name_arr=" + delete_lesson_str;

    const network$ = this.http.delete(req_url, options).cache(1);;
    network$.subscribe(
      () =>{console.log("delete lesson succeed : service")},
      (error)=>{console.log("delete lesson error", error)},
      ()=>{console.log("delete lesson complete: service")}
    )
    return network$;
  }
Example #11
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));
                
    }
 logout(): Observable<string> {
   return Observable.empty();
 }
Example #13
0
 public currentlyPlaying(): Observable<SongMetadata> {
     return Observable.empty();
 }
Example #14
0
 public songsList(): Observable<SongMetadata[]> {
     return Observable.empty();
 }
    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 #16
0
function detectTrends(quote$: rx.Observable<Quote>) : rx.Observable<Trend>  {
  return rx.Observable.empty<Trend>();
}
Example #17
0
 return Observable.defer(() => {
     this._synchronizedExcecutionInfo.next(ExecutionInfo.createBegin<TResult>());
     return Observable.empty<TResult>();
 })
 const closingSelector = (v: any) => {
   expect(Zone.current.name).toEqual(constructorZone1.name);
   return v % 2 === 0 ? Rx.Observable.of(v) : Rx.Observable.empty();
 };
 .catch((err: any): any => {
   this.errorService.notifyError(err);
   return Observable.empty();
 })
Example #20
0
function minFromPrevious(quote$: rx.Observable<Quote>, nbQuotes : number) : rx.Observable<number>  {
  return rx.Observable.empty<number>();
}
        it("should default to false", (done) => {
            var command: ReactiveCommand<any, boolean> = ReactiveCommand.createFromObservable((a) => Observable.of(true), Observable.empty<boolean>());

            command.canExecute.take(1).subscribe(can => {
                expect(can).to.be.false;
                done();
            }, err => done(err));
        });
Example #22
0
 observable1 = constructorZone1.run(() => {
   return Rx.Observable.empty();
 });
Example #23
0
function parseRawStream(raw$: rx.Observable<string>) : rx.Observable<Quote>  {
  return rx.Observable.empty<Quote>();
}