當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Observable.forkJoin方法代碼示例

本文整理匯總了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())
		)
	}
開發者ID:justinrjoseph,項目名稱:angular-2-exercises,代碼行數:9,代碼來源:github-profile.service.ts

示例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);
 }
開發者ID:phifour,項目名稱:angular2starter,代碼行數:11,代碼來源:httptest.service.ts

示例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));
  }
開發者ID:bryongloden,項目名稱:rumpel,代碼行數:13,代碼來源:images.service.ts

示例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));  
 }
開發者ID:kwanling,項目名稱:ng2test,代碼行數:15,代碼來源:app3.component.ts

示例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];
     });
 }
開發者ID:MicahFulton,項目名稱:GithubOrgSearch,代碼行數:14,代碼來源:repo.ts

示例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();

      });
    });
開發者ID:eventures-io,項目名稱:ng2-rx,代碼行數:14,代碼來源:backend.service.ts

示例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));
 }
開發者ID:chipster,項目名稱:chipster-web,代碼行數:15,代碼來源:upload.service.ts

示例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),
   );
 }
開發者ID:blmsl,項目名稱:memories,代碼行數:16,代碼來源:auth.service.ts

示例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)
         );  
 }
開發者ID:kwanling,項目名稱:ng2test,代碼行數:17,代碼來源:app3.component.ts

示例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
    }
開發者ID:aroget,項目名稱:ng2-countries,代碼行數:17,代碼來源:index.ts

示例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);
    })
  }
開發者ID:chgc,項目名稱:presentation-rxjs,代碼行數:17,代碼來源:demo3.component.ts

示例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 => {
開發者ID:vnctaing,項目名稱:stethoscope,代碼行數:45,代碼來源:bitbucket.service.ts

示例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);
         }
     }
 },
開發者ID:hardyoyo,項目名稱:angular2-ui-prototype,代碼行數:20,代碼來源:item-create.component.ts

示例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)
   )
 }
開發者ID:creedarky,項目名稱:angular2-music,代碼行數:6,代碼來源:albums-service.service.ts

示例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())
   );
 }
開發者ID:Alberto-Velez,項目名稱:Mean_Stack-,代碼行數:8,代碼來源:demo.service.ts


注:本文中的rxjs/Rx.Observable.forkJoin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。