当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript operators.refCount函数代码示例

本文整理汇总了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;未经允许,请勿转载。