本文整理匯總了TypeScript中rxjs/Rx.Observable.range方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.range方法的具體用法?TypeScript Observable.range怎麽用?TypeScript Observable.range使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.range方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
observable1 = constructorZone1.run(() => {
return Rx.Observable.range(0, 3)
.map(function(x: any) {
return Rx.Observable.range(x, 3);
})
.switch ();
});
示例2: function
observable1 = constructorZone1.run(() => {
return Rx.Observable.forkJoin(
Rx.Observable.range(1, 2), Rx.Observable.from([4, 5]), function(x, y) {
expect(Zone.current.name).toEqual(constructorZone1.name);
return x + y;
});
});
示例3: it
it('should count a range().take(1) source observable', (done: MochaDone) => {
Rx.Observable.range(1, 10).take(1).count().subscribe(
(value: number) => {
expect(value).to.equal(1);
}, (x) => {
done(new Error('should not be called'));
}, () => {
done();
});
});
示例4: second
.retryWhen((attempts:any) => {
return Observable
.range(1, 3)
.zip(attempts, (i) => {
return i;
})
.flatMap( (i) => {
console.log("Unable to fetch...delay retry by " + i + " second(s)")
return Observable.timer(i * 1000);
})
})
示例5: it
it('should subscribe to observables that are an instanceof Rx.Observable', (done) => {
const expected = [1, 2, 3];
const result = Rx.Observable.range(1, 3);
const subscriber = new OuterSubscriber<number, number>(x => {
expect(expected.shift()).to.be.equal(x);
}, () => {
done(new Error('should not be called'));
}, () => {
expect(expected).to.be.empty;
done();
});
subscribeToResult(subscriber, result);
});
示例6: constructor
constructor() {
this.raw = [];
this.numberStream = Rx.Observable.range(0,10);
this.numberStream
.subscribe(n => this.raw.push(n));
this.numberStream
.filter(n => n % 3 === 0)
.map(n => n * 3)
.toArray()
.subscribe(numbers => this.numbers = numbers);
this.numberStream
.scan((sum: number, n: number) => sum + n)
.subscribe((total: number) => this.total = total);
}
示例7: constructor
// notify completion of observable.
constructor() {
var d1 = Observable.throw(new Error("error"));
d1.subscribe(
x => console.log(x),
err => console.error(err),
() => console.log("completed")
);
var d2 = Observable.range(1,10);
d2.subscribe(
x => console.log(x),
err => console.error(err),
() => console.log("completed")
);
// // own counter
// var counter = 0;
// var d3 = Observable
// .interval(1000)
// .flatMap(x => counter < 10 ? Observable.of(counter++) : Observable.throw("error"));
// d3.subscribe(
// x => console.log(x),
// err => console.error(err),
// () => console.log("completed")
// );
var c = 0;
var d4 = Observable
.interval(1000)
.take(10)
.map(x => c++);
d4.subscribe(
x => console.log(x),
err => console.error(err),
() => console.log("completed")
);
}
示例8:
let generateRequests = (numberOfRequests: number) => {
let requestStream = Observable
.range(startingPage + 1, numberOfRequests - 1)
.flatMap(pageNumber => {
return this.getPageRequest(pageNumber);
})
requestStream.subscribe(
// On Value
(benchData: IBenchData) => {
results.next(benchData.transactions)
},
// On Error
(error: any) => {
console.log("Unable to execute request for additional remote resources")
results.error(error)
},
// On Complete
() => {
results.complete()
})
}
示例9: constructor3
constructor3() {
console.log(new Observable());
var d1 = Observable.empty();
d1.subscribe(x => console.log(x));
var d2 = Observable.range(1, 5);
d2.subscribe(x => console.log(x));
var d3 = Observable.fromArray([1,2,3]);
d3.subscribe(x => console.log(x));
var d4 = Observable.of(1);
d4.subscribe(x => console.log(x));
var d5 = Observable.of(1,2,3);
d5.subscribe(x => console.log(x));
var d6 = Observable.of([1,2,3]);
d6.subscribe(x => console.log(x));
}
示例10:
observable2 = constructorZone2.run(() => {
return Rx.Observable.range(3, 4);
});