本文整理汇总了TypeScript中rxjs/Rx.Observable.forkJoin方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.forkJoin方法的具体用法?TypeScript Observable.forkJoin怎么用?TypeScript Observable.forkJoin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs/Rx.Observable
的用法示例。
在下文中一共展示了Observable.forkJoin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getProfile
getProfile(username) {
this._profileUrl = "https://api.github.com/users/" + username;
this._followersUrl = "https://api.github.com/users/" + username + "/followers";
return Observable.forkJoin(
this._http.get(this._profileUrl).map(res => res.json()),
this._http.get(this._followersUrl).map(res => res.json())
)
}
示例2: getImageIDs
getImageIDs(ids) {
console.log('ids', ids);
var books = null;
var movies = null;
var obs: any[];
obs = [];
for (var i = 0; i < ids.length; i++) {
obs.push(this.http.get(this.getPhotoURL(ids[i].id)).map((res: Response) => res.json()));
}
return Observable.forkJoin(obs);
}
示例3: loadAll
loadAll() {
if (this._store.images.length > 0) return Observable.of(this._store.images);
Observable.forkJoin(
this._hat.getAllValuesOf('photos', 'dropbox')
.map(data => data.map(this.imgMap)),
this._hat.getAllValuesOf('metadata', 'dropbox_plug')
).subscribe(responses => {
this._store.images = responses[0];
this._authBearer = "Bearer " + responses[1][0]['access_token'];
this.downloadImages();
}, err => console.log('There was an error loading images from HAT', err));
}
示例4: constructor5
// forkJoin pattern
constructor5() {
console.log(new Observable());
var userStream = Observable.of({
userId: 1, username: 'kling'
}).delay(2000);
var tweetStream = Observable.of([1,2,3]).delay(1500);
var c = Observable.forkJoin(userStream, tweetStream)
.map(joined => new Object({user: joined[0], tweet: joined[1]}));
//c.subscribe(x => console.log(x));
c.subscribe(x => console.log(x));
}
示例5: ngOnInit
ngOnInit() {
let request = new Request({
method: RequestMethod.Get,
url: `https://api.github.com/repos/${this.organization}/${this.repo}/readme`,
headers: new Headers({'Accept': 'application/vnd.github.full.html'})
});
Observable.forkJoin(
this.http.request(request).map(res => res.text()),
this.http.get(`https://api.github.com/repos/${this.organization}/${this.repo}/commits?per_page=25`).map(res => res.json())
).subscribe(res => {
this.markdown = res[0];
this.commits = res[1];
});
}
示例6:
return Observable.create(observer => {
Observable.forkJoin(
that.getEndangeredMamals(),
that.getEndageredBirds()
).subscribe(data => {
list = data[0];
list.push.apply(list, data[1]);
observer.next(list);
observer.complete();
});
});
示例7: startUpload
startUpload(sessionId: string, file: any) {
Observable.forkJoin(
this.configService.getFileBrokerUrl(),
this.createDataset(sessionId, file.name)
).subscribe((value: [string, Dataset]) => {
const url = value[0];
const dataset = value[1];
file.chipsterTarget = `${url}/sessions/${sessionId}/datasets/${
dataset.datasetId
}?token=${this.tokenService.getToken()}`;
file.chipsterSessionId = sessionId;
file.chipsterDatasetId = dataset.datasetId;
file.resume();
}, err => this.restErrorService.showError("upload failed", err));
}
示例8: uploadUser
private uploadUser(user: firebase.User): Observable<[User, UserPrivate]> {
const platformUser = new User({
$key: user.uid,
displayName: user.displayName,
photoURL: user.photoURL,
updatedAt: firebase.database.ServerValue.TIMESTAMP,
});
const platformUserPrivate = new UserPrivate({
$key: user.uid,
email: user.email,
});
return Observable.forkJoin(
this.userService.updateUser(platformUser),
this.userPrivateService.updateUserPrivate(platformUserPrivate),
);
}
示例9: constructor6
// catch observable error pattern
constructor6() {
console.log(new Observable());
var userStream = Observable.throw(new Error("Something failed"));
var tweetStream = Observable.of([1,2,3]).delay(1500);
var c = Observable.forkJoin(userStream, tweetStream)
.map(joined => new Object({user: joined[0], tweet: joined[1]}));
//c.subscribe(x => console.log(x));
c.subscribe(
x => console.log(x),
error => console.error(error)
);
}
示例10: getData
getData() {
const countryDetails$ = this.countryDetailsService.getData(this.country, this.lang);
const weather$ = this.weatherService.getData(this.lat, this.lng);
const images$ = this.imagesService.getData(this.name);
const countrydescription$ = this.countryDescriptionService.getData(this.name, this.lang);
Rx.Observable.forkJoin([countryDetails$, weather$, images$, countrydescription$]).subscribe(
res => {
this.countrydetails = res[0].geonames[0],
this.weatherdetails = res[1].weatherObservation,
this.images = res[2].hits.length == 3 ? res[2].hits : null,
this.countrydescription = res[3].geonames
},
err => console.log(err)
);
// TODO handle error
}
示例11: ngOnInit
ngOnInit() {
console.clear();
Observable.forkJoin(
this.http.get('http://jsonplaceholder.typicode.com/todos').map(res => res.json()),
this.http.get('https://jsonplaceholder.typicode.com/users').map(res => res.json())
).subscribe(
data => console.log(data),
err => console.error(err.message)
);
let p1 = this.http.get('http://jsonplaceholder.typicode.com/todos').map(res => res.json()).toPromise();
let p2 = this.http.get('https://jsonplaceholder.typicode.com/users').map(res => res.json()).toPromise();
Promise.all([p1, p2]).then(values => {
console.log('Promise',values);
})
}
示例12: Date
.subscribe(prContainer => {
// get first page of pull requests
let pullRequests = prContainer.values;
// Calc number of other pages to get
let nbPages = Math.ceil(prContainer.size / prContainer.pagelen);
if (nbPages === 1) {
// Return the result to the observers
observer.next(pullRequests);
}
// Build array of fetch to subscribe
let fetchPages: any[] = [];
for (let i = 2; i <= nbPages; i++) {
fetchPages.push(this.fetchPullRequestPage(i));
}
// get synchrone result of all fetch
Observable.forkJoin(fetchPages).subscribe(datas => {
let dataArray: any = datas;
dataArray.forEach((data: any) => {
pullRequests = pullRequests.concat(data.values);
});
let modelPullRequests: PullRequest[] = pullRequests.map((pullRequest: any) => {
let modelPullRequest: PullRequest = {
id: pullRequest.id,
title: pullRequest.title,
description: pullRequest.description,
merge_commit: pullRequest.merge_commit,
author: {userName: pullRequest.username,
displayName: pullRequest.display_name,
uuid: pullRequest.uuid},
createdOn: new Date(pullRequest.created_on),
updatedOn: new Date(pullRequest.updated_on),
commentCount: pullRequest.comment_count
};
return modelPullRequest;
});
observer.next(modelPullRequests);
});
}, err => {
示例13:
this.dspaceService.createItem(this.item.sanitize(), token, currentContext.id).subscribe(response => {
if(response.status == 200) {
this.item.id = JSON.parse(response.text()).id;
if(this.files.length > 0) {
let bitStreamObservables = new Array<any>();
for(let file of this.files) {
bitStreamObservables.push(this.dspaceService.addBitstream(this.item, file, token));
}
Observable.forkJoin(bitStreamObservables).subscribe(bitstreamResponses => {
this.finish(this.item.name, currentContext);
},
errors => {
this.finish(this.item.name, currentContext);
});
}
else {
this.finish(this.item.name, currentContext);
}
}
},
示例14: getAlbum
getAlbum(id) {
return Observable.forkJoin(
this.http.get(`api/albums/${id}`).map(res => res.json().album),
this.http.get(`api/albums/${id}/tracks`).map(res => res.json().tracks)
)
}
示例15: 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())
);
}