当前位置: 首页>>代码示例>>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;未经允许,请勿转载。