本文整理汇总了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();
}
示例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())
);
}
示例3: subscribeToSaveResponse
private subscribeToSaveResponse(result: Observable<Tamanhos>) {
result.subscribe((res: Tamanhos) =>
this.onSaveSuccess(res), (res: Response) => this.onSaveError());
}
示例4: handleError
private handleError (error: Response) {
console.error(error);
return Observable.throw(error.json().error || 'Server Error');
}
示例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())
);
}
示例6: detectTrends
function detectTrends(quote$: rx.Observable<Quote>) : rx.Observable<Trend> {
return rx.Observable.empty<Trend>();
}
示例7: subscribeToSaveResponse
private subscribeToSaveResponse(result: Observable<PersonelHotpersonel>) {
result.subscribe((res: PersonelHotpersonel) =>
this.onSaveSuccess(res), (res: Response) => this.onSaveError(res));
}
示例8:
observable1 = constructorZone1.run(() => {
return Rx.Observable.timer(10, 20);
});
示例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
示例10: check
check() {
return Observable.of(this.loggedIn);
}