• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript operators.refCount函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中rxjs/operators.refCount函数的典型用法代码示例。如果您正苦于以下问题:TypeScript refCount函数的具体用法?TypeScript refCount怎么用?TypeScript refCount使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了refCount函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: convert

  convert(entry: INamespace): Namespace {
    const namespace = new Namespace(entry);

    namespace.applications = this.applicationBindingService
      .getBoundApplications(namespace.getId())
      .pipe(
        map(boundNamespaces => {
          const namespaces = boundNamespaces['applications'];
          return namespaces ? namespaces.length : 0;
        }),
        catchError(() => {
          return of(0);
        }),
        publishReplay(1),
        refCount()
      );

    const servicesUrl = `${
      AppConfig.k8sApiServerUrl
    }namespaces/${namespace.getId()}/services`;
    namespace.services = this.http.get<any>(servicesUrl).pipe(
      map(res => {
        return res.items.length;
      }),
      catchError(() => {
        return of(0);
      }),
      publishReplay(1),
      refCount()
    );

    return namespace;
  }
开发者ID:marynaKhromova,项目名称:console,代码行数:33,代码来源:namespace-data-converter.ts


示例2: constructor

  constructor(ref: DocumentReference) {
    this.ref = ref;

    this.index = new PackedIndex();

    this.data().subscribe(data => this.index.setInstitution(data));

    this.gradeDistribution = this.data().pipe(
      switchMap(data => Axios.get(`${data.cloudFunctionsUrl}/api/grades`)),
      map(
        (response: { data: any }) =>
          Object.freeze(response.data) as Distribution
      ),
      publishReplay(1),
      refCount()
    );
    this.courseRanking = combineLatest(
      this.getGradeDistribution().pipe(
        map(distribution => {
          return Object.entries(distribution).reduce((obj, [course, data]) => {
            return {
              ...obj,
              [course]: 2 * Object.values(data).reduce((a, b) => a + b, 0)
            };
          }, {});
        })
      ),
      this.index.getSequences().pipe(
        switchMap(sequences => {
          return combineLatest(
            sequences.map(sequence => this.index.getSparseSequence(sequence))
          );
        })
      )
    ).pipe(
      map(([courseRanking, sparseSequences]) => {
        sparseSequences.forEach(sequence => {
          // Promote the rank of each course in the sequence to the max.
          const max =
            sequence
              .map(course => courseRanking[course] | 0)
              .reduce((a, b) => Math.max(a, b)) + 1;
          sequence.forEach(course => (courseRanking[course] = max));
        });
        return courseRanking;
      }),
      publishReplay(1),
      refCount()
    );
  }
开发者ID:kevmo314,项目名称:canigraduate.uchicago.edu,代码行数:50,代码来源:institution.ts


示例3: it

    it('should be repeatable using a ReplaySubject', () => {
      function subjectFactory() { return new ReplaySubject(1); }
      const source =     cold('-1-2-3----4-|                        ');
      const sourceSubs =     ['^           !                        ',
                              '            ^           !            ',
                              '                        ^           !'];
      const multicasted = source.pipe(
        multicast(subjectFactory),
        refCount()
      );
      const subscribe1 =      's                                    ';
      const expected1 =       '-1-2-3----4--1-2-3----4--1-2-3----4-|';
      const subscribe2 =      '    s                                ';
      const expected2 =       '    23----4--1-2-3----4--1-2-3----4-|';

      expectObservable(
        hot(subscribe1).pipe(tap(() => {
          expectObservable(multicasted.pipe(repeat(3))).toBe(expected1);
        }))
      ).toBe(subscribe1);

      expectObservable(
        hot(subscribe2).pipe(tap(() => {
          expectObservable(multicasted.pipe(repeat(3))).toBe(expected2);
        }))
      ).toBe(subscribe2);

      expectSubscriptions(source.subscriptions).toBe(sourceSubs);
    });
开发者ID:DallanQ,项目名称:rxjs,代码行数:29,代码来源:multicast-spec.ts


示例4: getNavData

 getNavData(): Observable<any> {
   if (!this._navData) {
     this._navData = this.httpClient.get(environment.serverUrl + 'application')
       .pipe(publishReplay(), refCount());
   }
   return this._navData;
 }
开发者ID:grails-profiles,项目名称:angular,代码行数:7,代码来源:nav.service.ts


示例5: it

  it('should unsub from the source when all other subscriptions are unsubbed', (done: MochaDone) => {
    let unsubscribeCalled = false;
    const connectable = new Observable<boolean>(observer => {
      observer.next(true);
      return () => {
        unsubscribeCalled = true;
      };
    }).pipe(publish());

    const refCounted = connectable.pipe(refCount());

    const sub1 = refCounted.subscribe(() => {
      //noop
    });
    const sub2 = refCounted.subscribe(() => {
      //noop
    });
    const sub3 = refCounted.subscribe((x: any) => {
      expect((connectable as any)._refCount).to.equal(1);
    });

    sub1.unsubscribe();
    sub2.unsubscribe();
    sub3.unsubscribe();

    expect((connectable as any)._refCount).to.equal(0);
    expect(unsubscribeCalled).to.be.true;
    done();
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:29,代码来源:refCount-spec.ts


示例6: getLogPerson

 public getLogPerson(id: string): Observable<ActionLog[]> {
   if (!this._logs) {
     this._logs = this._http
       .get('action-log/list?id=' + id + '&context=person')
       .pipe(map(this.deserializeList), publishReplay(), refCount());
   }
   return this._logs;
 }
开发者ID:digitaldeacon,项目名称:memberhive,代码行数:8,代码来源:audit.service.ts


示例7: cold

  '(dis)connecting hot one', () => {
    const source = cold('--1-2---3-4--5-|');
    const sourceSubs =  '^              !';
    const expected =    '--1-2---3-4--5-|';

    const result = source.pipe(
      publish(),
      refCount()
    );

    expectObservable(result).toBe(expected);
    expectSubscriptions(source.subscriptions).toBe(sourceSubs);
  });
开发者ID:DallanQ,项目名称:rxjs,代码行数:13,代码来源:refCount-spec.ts



注:本文中的rxjs/operators.refCount函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript operators.repeat函数代码示例发布时间:2022-05-25
下一篇:
TypeScript operators.reduce函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap