当前位置: 首页>>代码示例>>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;未经允许,请勿转载。