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


TypeScript operators.publishReplay函數代碼示例

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


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

export function publishReplay<T, R>(this: Observable<T>, bufferSize?: number,
                                    windowTime?: number,
                                    selectorOrScheduler?: SchedulerLike | OperatorFunction<T, R>,
                                    scheduler?: SchedulerLike): Observable<R> | ConnectableObservable<R> {

  return higherOrder<T, R>(bufferSize, windowTime, selectorOrScheduler as any, scheduler)(this);
}
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:7,代碼來源:publishReplay.ts

示例4: start

  public async start(httpServerInfo?: HttpServerInfo) {
    this.log.debug('starting legacy service');

    const update$ = this.configService.getConfig$().pipe(
      tap(config => {
        if (this.kbnServer !== undefined) {
          this.kbnServer.applyLoggingConfiguration(config.toRaw());
        }
      }),
      tap({ error: err => this.log.error(err) }),
      publishReplay(1)
    ) as ConnectableObservable<Config>;

    this.configSubscription = update$.connect();

    // Receive initial config and create kbnServer/ClusterManager.
    this.kbnServer = await update$
      .pipe(
        first(),
        mergeMap(async config => {
          if (this.env.isDevClusterMaster) {
            await this.createClusterManager(config);
            return;
          }

          return await this.createKbnServer(config, httpServerInfo);
        })
      )
      .toPromise();
  }
開發者ID:rashidkpc,項目名稱:kibana,代碼行數:30,代碼來源:legacy_service.ts

示例5: 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

示例6: setupLogging

  private async setupLogging() {
    // Stream that maps config updates to logger updates, including update failures.
    const update$ = this.configService.getConfig$().pipe(
      // always read the logging config when the underlying config object is re-read
      switchMap(() => this.configService.atPath('logging', LoggingConfig)),
      map(config => this.loggingService.upgrade(config)),
      // This specifically console.logs because we were not able to configure the logger.
      // eslint-disable-next-line no-console
      tap({ error: err => console.error('Configuring logger failed:', err) }),
      publishReplay(1)
    ) as ConnectableObservable<void>;

    // Subscription and wait for the first update to complete and throw if it fails.
    const connectSubscription = update$.connect();
    await update$.pipe(first()).toPromise();

    // Send subsequent update failures to this.shutdown(), stopped via loggingConfigSubscription.
    this.loggingConfigSubscription = update$.subscribe({
      error: err => this.shutdown(err),
    });

    // Add subscription we got from `connect` so that we can dispose both of them
    // at once. We can't inverse this and add consequent updates subscription to
    // the one we got from `connect` because in the error case the latter will be
    // automatically disposed before the error is forwarded to the former one so
    // the shutdown logic won't be called.
    this.loggingConfigSubscription.add(connectSubscription);
  }
開發者ID:horacimacias,項目名稱:kibana,代碼行數:28,代碼來源:index.ts

示例7: start

  public async start(startDeps: CoreStart) {
    const { setupDeps } = this;
    if (!setupDeps) {
      throw new Error('Legacy service is not setup yet.');
    }
    this.log.debug('starting legacy service');

    const update$ = this.coreContext.configService.getConfig$().pipe(
      tap(config => {
        if (this.kbnServer !== undefined) {
          this.kbnServer.applyLoggingConfiguration(config.toRaw());
        }
      }),
      tap({ error: err => this.log.error(err) }),
      publishReplay(1)
    ) as ConnectableObservable<Config>;

    this.configSubscription = update$.connect();

    // Receive initial config and create kbnServer/ClusterManager.
    this.kbnServer = await update$
      .pipe(
        first(),
        mergeMap(async config => {
          if (this.coreContext.env.isDevClusterMaster) {
            await this.createClusterManager(config);
            return;
          }
          return await this.createKbnServer(config, setupDeps, startDeps);
        })
      )
      .toPromise();
  }
開發者ID:simianhacker,項目名稱:kibana,代碼行數:33,代碼來源:legacy_service.ts

示例8: 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

示例9: getCurrentNodes

  /**
   * Get an observable of the current nodes (the ones that match the current URL)
   * We use `publishReplay(1)` because otherwise subscribers will have to wait until the next
   * URL change before they receive an emission.
   * See above for discussion of using `connect`.
   */
  private getCurrentNodes(navigationViews: Observable<NavigationViews>): Observable<CurrentNodes> {
    const currentNodes = combineLatest(
      navigationViews.pipe(map(views => this.computeUrlToNavNodesMap(views))),
      this.location.currentPath,

      (navMap, url) => {
        const urlKey = url.startsWith('api/') ? 'api' : url;
        return navMap.get(urlKey) || { '' : { view: '', url: urlKey, nodes: [] }};
      })
      .pipe(publishReplay(1));
    (currentNodes as ConnectableObservable<CurrentNodes>).connect();
    return currentNodes;
  }
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:19,代碼來源:navigation.service.ts

示例10: setup

  public async setup(): Promise<ElasticsearchServiceSetup> {
    this.log.debug('Setting up elasticsearch service');

    const clients$ = this.coreContext.configService
      .atPath('elasticsearch', ElasticsearchConfig)
      .pipe(
        filter(() => {
          if (this.subscription !== undefined) {
            this.log.error('Clients cannot be changed after they are created');
            return false;
          }

          return true;
        }),
        switchMap(
          config =>
            new Observable<CoreClusterClients>(subscriber => {
              this.log.debug(`Creating elasticsearch clients`);

              const coreClients = {
                config,
                adminClient: this.createClusterClient('admin', config),
                dataClient: this.createClusterClient('data', config),
              };

              subscriber.next(coreClients);

              return () => {
                this.log.debug(`Closing elasticsearch clients`);

                coreClients.adminClient.close();
                coreClients.dataClient.close();
              };
            })
        ),
        publishReplay(1)
      ) as ConnectableObservable<CoreClusterClients>;

    this.subscription = clients$.connect();

    return {
      legacy: { config$: clients$.pipe(map(clients => clients.config)) },

      adminClient$: clients$.pipe(map(clients => clients.adminClient)),
      dataClient$: clients$.pipe(map(clients => clients.dataClient)),

      createClient: (type: string, clientConfig: ElasticsearchClientConfig) => {
        return this.createClusterClient(type, clientConfig);
      },
    };
  }
開發者ID:horacimacias,項目名稱:kibana,代碼行數:51,代碼來源:elasticsearch_service.ts


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