本文整理匯總了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();
});
示例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)));
});
示例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);
}
}
示例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()};
}));
示例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;
});
});
示例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));
示例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'));