當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Rx.Observable類代碼示例

本文整理匯總了TypeScript中rxjs/Rx.Observable的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable類的具體用法?TypeScript Observable怎麽用?TypeScript Observable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Observable類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

 constructor() {
   this.errorObservable = Observable.create((observer:Observer<any>) => {
     this.errorObserver = observer;
   }).share();
 }
開發者ID:allash,項目名稱:restlet-samples-angular2-rxjs,代碼行數:5,代碼來源:error.notifier.ts

示例2: constructor

    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())
        );


    }
開發者ID:lricoy,項目名稱:angular2-rxjs-first-impression,代碼行數:76,代碼來源:app.component.ts

示例3: subscribeToSaveResponse

 private subscribeToSaveResponse(result: Observable<Tamanhos>) {
     result.subscribe((res: Tamanhos) =>
         this.onSaveSuccess(res), (res: Response) => this.onSaveError());
 }
開發者ID:rogrs,項目名稱:loja,代碼行數:4,代碼來源:tamanhos-dialog.component.ts

示例4: handleError

 private handleError (error: Response) {
     console.error(error);
     return Observable.throw(error.json().error || 'Server Error');
 }
開發者ID:rastin71,項目名稱:simple_mean,代碼行數:4,代碼來源:ars.service.ts

示例5: getBooksAndMovies

 // 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())
     );
 }
開發者ID:Muthukumaruma,項目名稱:angular2-http-demo,代碼行數:8,代碼來源:demo.service.ts

示例6: detectTrends

function detectTrends(quote$: rx.Observable<Quote>) : rx.Observable<Trend>  {
  return rx.Observable.empty<Trend>();
}
開發者ID:RxHandsOn,項目名稱:MarketData,代碼行數:3,代碼來源:Stock.ts

示例7: subscribeToSaveResponse

 private subscribeToSaveResponse(result: Observable<PersonelHotpersonel>) {
     result.subscribe((res: PersonelHotpersonel) =>
         this.onSaveSuccess(res), (res: Response) => this.onSaveError(res));
 }
開發者ID:ATS01Dev,項目名稱:HotMan,代碼行數:4,代碼來源:personel-hotpersonel-dialog.component.ts

示例8:

 observable1 = constructorZone1.run(() => {
   return Rx.Observable.timer(10, 20);
 });
開發者ID:jahtalab,項目名稱:zone.js,代碼行數:3,代碼來源:rxjs.timer.spec.ts

示例9:

 .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
開發者ID:lee-woodridge,項目名稱:angular2-course,代碼行數:5,代碼來源:jquery.component.ts

示例10: check

check() {
  return Observable.of(this.loggedIn);
  }
開發者ID:MOHAMMADArsalan,項目名稱:SalemanApp_ng02,代碼行數:3,代碼來源:Auth.ts


注:本文中的rxjs/Rx.Observable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。