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


TypeScript Observable.range方法代碼示例

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


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

示例1: it

  it('should not work after has been disposed', function(done) {
    let number$ = Rx.Observable
      .range(1, 3)
      .concatMap(x => Rx.Observable.of(x).delay(150));

    function app(sources: any): any {
      return {other: number$};
    }

    let {sources, run} = setup(app, {
      other: (num$: any) => Observable.from(num$).map((num: any) => 'x' + num),
    });

    let dispose: any;
    sources.other.subscribe(function(x: any) {
      assert.notStrictEqual(x, 'x3');
      if (x === 'x2') {
        dispose();
        setTimeout(() => {
          done();
        }, 100);
      }
    });
    dispose = run();
  });
開發者ID:joeldentici,項目名稱:cyclejs,代碼行數:25,代碼來源:index.ts

示例2: callback

 return source.retryWhen(errors => {
     return Observable
         .zip(Observable.range(1, backoffRetries), errors, (i, e) => [i, e])
         .do(data => callback(data[1]))
         .flatMap(data => Observable.timer(data[0] * data[0] * backoffInterval))
         .concat(Observable
             .timer(pollingInterval, pollingInterval)
             .zip(errors, (timer, error) => error)
             .do(error => callback(error)));
 });
開發者ID:tierratelematics,項目名稱:prettygoat,代碼行數:10,代碼來源:TypesUtil.ts

示例3:

const starsInit$Fac = (stars: iStar[]): Observable<iStar[]> => {
  if (stars.length === 0) { // at START_CLICKED, generate a starsInit$
    return Observable.range(1, config.stars.count)
      .map(item => {
        const size = 1 + Math.random() * 1.5;
        const speed = size > 1.6 ? 0.25 : 0.05;
        const color = '#ffffff'; // whilte
        return {
          x: Math.random() * config.canvas.width,
          y: Math.random() * config.canvas.height,
          size: size,
          speed: speed,
          color: color
        }
      })
      .toArray()
  }
  if (stars.length > 0) { // at CONTINUE_CLICKED, use the stars in the game state
    return Observable.of(stars);
  }
}
開發者ID:timathon,項目名稱:rx-space,代碼行數:21,代碼來源:stars.ts

示例4: Date

 streamFactory.setup(s => s.from(It.isAny(), It.isAny(), It.isAny())).returns(_ => Observable.range(1, 5).map(n => {
     return {type: "increment", payload: n, timestamp: new Date()};
 }));
開發者ID:tierratelematics,項目名稱:prettygoat,代碼行數:3,代碼來源:ProjectionRunnerSpec.ts

示例5: Number

import {Observable} from 'rxjs';
import constants from '../constants/index';
import StarSky from './starsky';

export const StarStream = Observable.range(1,constants.STAR_NUMBER)
  .map(() =>({
    x: Number(Math.random() * StarSky.canvas.width),
    y: Number(Math.random() * StarSky.canvas.height),
    size: Math.random() * 3 + 1
  }))
  .toArray()
  .flatMap(starArray => {
    return Observable.interval(constants.SPEED)
      .map(() => {
        starArray.forEach(star => {
          if(star.y >= StarSky.canvas.height) {
            star.y = 0;
          }
          star.y += 3;
        })
        return starArray;
      });
  });
開發者ID:graforlock,項目名稱:spaceship-game,代碼行數:23,代碼來源:starstream.ts

示例6:

import { Observable } from "rxjs";

const smallNumbers$ =
    Observable.interval(500)
        .take(5);

const largeNumbers$ = Observable.range(101, 10);

const numberRange$ = smallNumbers$.concat(largeNumbers$);

const even$ = numberRange$.filter(num => (num % 2 == 0));

even$.subscribe(num => console.log(num));
開發者ID:Meligy,項目名稱:rxjs-samples,代碼行數:13,代碼來源:07-operators.ts

示例7:

import { Observable } from "rxjs"

// create an observable sequence of 5 integers, starting from 1
var source = Observable.range(1, 5);

// Prints out each item
var subscription = source.subscribe(
    x => console.log('onNext: %s', x),
    e => console.log('onError: %s', e),
    () => console.log('onCompleted'));
開發者ID:JasonGoemaat,項目名稱:webpack-test,代碼行數:10,代碼來源:rxtest.ts


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