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


TypeScript operators.publishLast函數代碼示例

本文整理匯總了TypeScript中rxjs/operators.publishLast函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript publishLast函數的具體用法?TypeScript publishLast怎麽用?TypeScript publishLast使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了publishLast函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getContributors

  private getContributors() {
    const contributors = this.http.get<{[key: string]: Contributor}>(contributorsPath).pipe(
      // Create group map
      map(contribs => {
        const contribMap: { [name: string]: Contributor[]} = {};
        Object.keys(contribs).forEach(key => {
          const contributor = contribs[key];
          contributor.groups.forEach(group => {
            const contribGroup = contribMap[group] || (contribMap[group] = []);
            contribGroup.push(contributor);
          });
        });

        return contribMap;
      }),

      // Flatten group map into sorted group array of sorted contributors
      map(cmap => {
        return Object.keys(cmap).map(key => {
          const order = knownGroups.indexOf(key);
          return {
            name: key,
            order: order === -1 ? knownGroups.length : order,
            contributors: cmap[key].sort(compareContributors)
          } as ContributorGroup;
        })
        .sort(compareGroups);
      }),

      publishLast(),
    );

    (contributors as ConnectableObservable<ContributorGroup[]>).connect();
    return contributors;
  }
開發者ID:Cammisuli,項目名稱:angular,代碼行數:35,代碼來源:contributor.service.ts

示例2: getVersionInfo

 private getVersionInfo(navigationInfo: Observable<NavigationResponse>) {
   const versionInfo = navigationInfo.pipe(
     map(response => response.__versionInfo),
     publishLast(),
   );
   (versionInfo as ConnectableObservable<VersionInfo>).connect();
   return versionInfo;
 }
開發者ID:baconwaffles,項目名稱:angular,代碼行數:8,代碼來源:navigation.service.ts

示例3: it

it('should accept empty parameter', () => {
  // Here, TypeScript versions 3.1 and earlier infer Observable<any>. However,
  // the next version infers Observable<number>. It's not possible to specify
  // an upper bound for the TypeScript version used by dtslint, so an
  // expectation cannot be applied.
  // TODO: put the test back after Typescript > 3.2
  const a = of(1, 2, 3).pipe(publishLast());
});
開發者ID:jaychsu,項目名稱:RxJS,代碼行數:8,代碼來源:publishLast-spec.ts

示例4: getCategories

  private getCategories(): Observable<Category[]> {

    const categories = this.http.get<any>(resourcesPath).pipe(
      map(data => mkCategories(data)),
      publishLast(),
    );

    (categories as ConnectableObservable<Category[]>).connect();
    return categories;
  };
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:10,代碼來源:resource.service.ts

示例5: getNavigationViews

 private getNavigationViews(navigationInfo: Observable<NavigationResponse>): Observable<NavigationViews> {
   const navigationViews = navigationInfo.pipe(
     map(response => {
       const views = Object.assign({}, response);
       Object.keys(views).forEach(key => {
         if (key[0] === '_') { delete views[key]; }
       });
       return views as NavigationViews;
     }),
     publishLast(),
   );
   (navigationViews as ConnectableObservable<NavigationViews>).connect();
   return navigationViews;
 }
開發者ID:baconwaffles,項目名稱:angular,代碼行數:14,代碼來源:navigation.service.ts

示例6: fetchNavigationInfo

 /**
  * Get an observable that fetches the `NavigationResponse` from the server.
  * We create an observable by calling `http.get` but then publish it to share the result
  * among multiple subscribers, without triggering new requests.
  * We use `publishLast` because once the http request is complete the request observable completes.
  * If you use `publish` here then the completed request observable will cause the subscribed observables to complete too.
  * We `connect` to the published observable to trigger the request immediately.
  * We could use `.refCount` here but then if the subscribers went from 1 -> 0 -> 1 then you would get
  * another request to the server.
  * We are not storing the subscription from connecting as we do not expect this service to be destroyed.
  */
 private fetchNavigationInfo(): Observable<NavigationResponse> {
   const navigationInfo = this.http.get<NavigationResponse>(navigationPath)
     .pipe(publishLast());
   (navigationInfo as ConnectableObservable<NavigationResponse>).connect();
   return navigationInfo;
 }
開發者ID:baconwaffles,項目名稱:angular,代碼行數:17,代碼來源:navigation.service.ts

示例7:

export function publishLast<T>(this: Observable<T>): ConnectableObservable<T> {
  //TODO(benlesh): correct type-flow through here.
  return higherOrder<T>()(this) as ConnectableObservable<T>;
}
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:4,代碼來源:publishLast.ts


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