本文整理汇总了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'));