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


TypeScript rxjs.ReplaySubject類代碼示例

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


在下文中一共展示了ReplaySubject類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _getNpmPackageJson

/**
 * Get the NPM repository's package.json for a package. This is p
 * @param {string} packageName The package name to fetch.
 * @param {LoggerApi} logger A logger instance to log debug information.
 * @returns {Observable<JsonObject>} An observable that will put the pacakge.json content.
 * @private
 */
function _getNpmPackageJson(
  packageName: string,
  logger: logging.LoggerApi,
): Observable<JsonObject> {
  const url = `https://registry.npmjs.org/${packageName.replace(/\//g, '%2F')}`;
  logger.debug(`Getting package.json from ${JSON.stringify(packageName)}...`);

  let maybeRequest = npmPackageJsonCache.get(url);
  if (!maybeRequest) {
    const subject = new ReplaySubject<JsonObject>(1);

    const request = https.request(url, response => {
      let data = '';
      response.on('data', chunk => data += chunk);
      response.on('end', () => {
        try {
          const json = parseJson(data, JsonParseMode.Strict);
          subject.next(json as JsonObject);
          subject.complete();
        } catch (err) {
          subject.error(err);
        }
      });
      response.on('error', err => subject.error(err));
    });
    request.end();

    maybeRequest = subject.asObservable();
    npmPackageJsonCache.set(url, maybeRequest);
  }

  return maybeRequest;
}
開發者ID:fmalcher,項目名稱:angular-cli,代碼行數:40,代碼來源:npm.ts

示例2: concatMap

        concatMap(options => {
          const subject = new ReplaySubject<NpmRepositoryPackageJson>(1);

          const client = new RegistryClient({
            proxy: {
              http: options[0],
              https: options[1],
            },
          });
          client.log.level = 'silent';
          const params = {
            timeout: 30000,
          };

          client.get(
            fullUrl,
            params,
            (error: object, data: NpmRepositoryPackageJson) => {
            if (error) {
              subject.error(error);
            }

            subject.next(data);
            subject.complete();
          });

          maybeRequest = subject.asObservable();
          npmPackageJsonCache.set(fullUrl.toString(), maybeRequest);

          return maybeRequest;
        }),
開發者ID:iwe7,項目名稱:devkit,代碼行數:31,代碼來源:npm.ts

示例3: inject

 inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
   const responses: Response[] = [sampleResponse1, sampleResponse2];
   backend.connections.subscribe((c: MockConnection) => c.mockRespond(responses.shift() !));
   const responseObservable: ReplaySubject<Response> =
       backend.createConnection(sampleRequest1).response;
   responseObservable.subscribe(res => expect(res.text()).toBe('response1'));
   responseObservable.subscribe(
       res => expect(res.text()).toBe('response2'), null !, async.done);
 }));
開發者ID:Cammisuli,項目名稱:angular,代碼行數:9,代碼來源:mock_backend_spec.ts

示例4: replaySubject

 replaySubject() {
     let replaySubject$ = new ReplaySubject(2); // Buffer 2 values for new subscribers
     interval(300).pipe(
         take(5)
     ).subscribe(replaySubject$);
     replaySubject$.subscribe(val => console.log(`Replay subject 1: ${val}`)); // 0, 1, 2, 3, 4
     setTimeout(() => {
         replaySubject$.subscribe(val => console.log(`Replay subject 2: ${val}`)); // 1, 2, 3, 4
     }, 1000);
 }
開發者ID:mr-Deviant,項目名稱:sandbox,代碼行數:10,代碼來源:subjects.component.ts

示例5: Subject

  public static create<T = any>(server: T): ObservableSocketServer<T> {
    const init = new ReplaySubject<T>();
    init.next(server);

    return {
      init,
      connection: new Subject(),
      disconnect: new Subject(),
      server,
    };
  }
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:11,代碼來源:observable-socket.ts

示例6:

            (error: object, data: NpmRepositoryPackageJson) => {
            if (error) {
              subject.error(error);
            }

            subject.next(data);
            subject.complete();
          });
開發者ID:baconwaffles,項目名稱:angular-cli,代碼行數:8,代碼來源:npm.ts

示例7: async

 const bind = async (suboperation: RenderVariantOperation<V>) => {
   try {
     subject.next(await this.renderVariant(suboperation));
   }
   catch (exception) {
     if (operation.pessimistic === false) {
       subject.error(exception);
     }
   }
 };
開發者ID:sonukapoor,項目名稱:angular-ssr,代碼行數:10,代碼來源:application.ts

示例8: Date

 .subscribe(articles => {
     if (articleSubject.observers.length > 0) {
         articleSubject.next(articles);
         feed.lastUpdatedAt = new Date();
         setTimeout(
             () => this.fetchArticles(feed, articleSubject),
             600000,
         );
     } else {
         articleSubject.complete();
     }
 });
開發者ID:danhooper,項目名稱:home_page,代碼行數:12,代碼來源:rss.service.ts

示例9: handleMessage

 handleMessage(msg: proto.Message) {
   if (msg.type) {
     switch (msg.type) {
       case 'offer':
         log.webrtc('REMOTE OFFER', { offer: msg.offer })
         this.pc
           .setRemoteDescription({ type: 'offer', sdp: msg.offer })
           .then(() =>
             this.candidates.subscribe((ic) =>
               this.pc
                 .addIceCandidate(ic)
                 .catch((err) => log.webrtc('Failed to addIceCandidate', err))
             )
           )
           .then(() => this.pc.createAnswer())
           .then((answer) => this.pc.setLocalDescription(answer))
           .then(() => {
             const { sdp } = this.pc.localDescription as RTCSessionDescription
             log.webrtc('Send LOCAL ANSWER', { answer: sdp })
             this.send({ answer: sdp })
             this.sdpIsSent()
           })
           .catch((err) => this._onError(err))
         break
       case 'answer':
         log.webrtc('REMOTE ANSWER is received', { answer: msg.answer })
         this.pc
           .setRemoteDescription({ type: 'answer', sdp: msg.answer } as any)
           .then(() => {
             this.candidates.subscribe((ic) =>
               this.pc
                 .addIceCandidate(ic)
                 .catch((err) => log.webrtc(`${this.id}: Failed to add REMOTE Ice Candidate`, err))
             )
           })
           .catch((err) => this._onError(err))
         break
       case 'candidate':
         log.webrtc('REMOTE ICE CANDIDATE is received', msg.candidate)
         this.candidates.next(new env.RTCIceCandidate(msg.candidate as proto.IceCandidate))
         break
       default:
         this._onError(new Error('Buffer Protocol unknown message from the remote peer'))
     }
   } else {
     log.webrtc('REMOTE FINAL MESSAGE received')
     this.finalMessageReceived = true
     this.candidates.complete()
     if (this.finalMessageSent) {
       this.remotes.delete(this.id)
     }
   }
 }
開發者ID:openpaas-ng,項目名稱:netflux,代碼行數:53,代碼來源:Remote.ts

示例10: it

    it("reacts to save click", fakeAsync(() => {
      component.ngOnInit();
      component.click();
      httpAction.next({ url: '', method: HttpMethod.Post, isComplete: false });
      flush();
      expect(component.isSaving).toBeTruthy();

      httpAction.next({ url: '', method: HttpMethod.Post, isComplete: true });
      flush();
      expect(component.isSaving).toBeFalsy();
      expect(component.isListening).toBeFalsy();
    }));
開發者ID:OysteinAmundsen,項目名稱:gymsystems,代碼行數:12,代碼來源:save-button.component.spec.ts


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