當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。