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()) ) }
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); }
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)); }
// forkJoin pattern constructor5() { console.log(new Observable()); var userStream = Observable.of({ userId: 1, username: '******' }).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)); }
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]; }); }
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(); }); });
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)); }
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), ); }
// 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) ); }
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 }