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


TypeScript Subject.pipe方法代碼示例

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


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

示例1: it

  it('should convert observable obeject to ordinal object', done => {
    const aValue = new Subject();
    const bValue = new Subject();
    const BUFFER_COUNT = 4;

    const values = createObject(
      aValue.pipe(startWith('')),
      bValue.pipe(startWith('')),
    );

    subscription.add(
      combineTemplate(values)
        .pipe(bufferCount(BUFFER_COUNT))
        .subscribe(v => {
          /*tslint:disable:no-magic-numbers*/
          expect(v[0]).to.be.deep.eq(createObject('', ''));
          expect(v[1]).to.be.deep.eq(createObject('200', ''));
          expect(v[2]).to.be.deep.eq(createObject('200', '300'));
          expect(v[3]).to.be.deep.eq(createObject('OK', '300'));
          /*tslint:enable:no-magic-numbers*/
          done();
        }),
    );

    aValue.next('200');
    bValue.next('300');
    aValue.next('OK');
  });
開發者ID:brn,項目名稱:react-mvi,代碼行數:28,代碼來源:combine-template.spec.ts

示例2: useEffect

  useEffect(() => {
    const subject$ = new Subject<Actor<any>>();

    const actorSubscription = actor$.subscribe(subject$);

    const end = (cb: () => void) => {
      cb();
      (optionsRef.current.onFinish || noop)(dispatch);
      requesting$.next(false);
    };

    const subscription = observableMerge(
      subject$.pipe(
        rxFilter(requestActor.done.is),
        rxFilter((actor) => isEqual(actor.opts.parentActor.arg, lastArg.current)),
        rxTap((actor: typeof requestActor.done) => {
          end(() => (optionsRef.current.onSuccess || noop)(actor, dispatch));
        }),
      ),
      subject$.pipe(
        rxFilter(requestActor.failed.is),
        rxFilter((actor) => isEqual(actor.opts.parentActor.arg, lastArg.current)),
        rxTap((actor: typeof requestActor.failed) => {
          end(() => (optionsRef.current.onFail || noop)(actor, dispatch));
        }),
      ),
    ).subscribe();

    return () => {
      subscription.unsubscribe();
      actorSubscription.unsubscribe();
    };
  }, [requestActor]);
開發者ID:querycap,項目名稱:reactorx,代碼行數:33,代碼來源:useRequest.ts

示例3: ngOnInit

 ngOnInit() {
   this.time$ = this.store.select("tickReducer");
   this.hourBackward$ = new Subject();
   this.hourForward$ = new Subject();
   this.dayBackward$ = new Subject();
   this.dayForward$ = new Subject();
   this.merged$ = merge(
     this.hourBackward$.pipe(mapTo({type: HOUR_TICK, payload: -1})),
     this.hourForward$.pipe(mapTo({type: HOUR_TICK, payload: 1})),
     this.dayBackward$.pipe(mapTo({type: DAY_TICK, payload: -1})),
     this.dayForward$.pipe(mapTo({type: DAY_TICK, payload: 1})),
     interval(1000).pipe(mapTo({type: SECOND_TICK, payload: 1}))
   );
 }
開發者ID:screenm0nkey,項目名稱:angular2-examples-webpack,代碼行數:14,代碼來源:ngrx-clock-one.component.ts

示例4: it

  it('should multicast a ConnectableObservable', (done) => {
    const expected = [1, 2, 3, 4];

    const source = new Subject<number>();
    const connectable = source.pipe(multicast(new Subject<number>())) as ConnectableObservable<number>;
    const replayed = connectable.pipe(multicast(new ReplaySubject<number>())) as ConnectableObservable<number>;

    connectable.connect();
    replayed.connect();

    source.next(1);
    source.next(2);
    source.next(3);
    source.next(4);
    source.complete();

    replayed.pipe(
      tap({
        next(x) {
          expect(x).to.equal(expected.shift());
        },
        complete() {
          expect(expected.length).to.equal(0);
        }
      })
    ).subscribe(null, done, done);
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:27,代碼來源:multicast-spec.ts

示例5: return

 return Observable.create(obs => {
   const subscription = intersectionSubject.pipe(filter(entry => entry.target === attributes.element)).subscribe(obs);
   return () => {
     subscription.unsubscribe();
     observer.unobserve(attributes.element);
   };
 });
開發者ID:tjoskar,項目名稱:ng2-lazyload-image,代碼行數:7,代碼來源:intersection-listener.ts

示例6: fn

export default function createMutationBehaviorSubject<T>(
  value: T
): [Subject<(state: T) => T>, BehaviorSubject<T>] {
  const source = new BehaviorSubject<T>(value);
  const sink = new Subject<(state: T) => T>();
  sink.pipe(map(fn => fn(source.value))).subscribe(source);
  return [sink, source];
}
開發者ID:kevmo314,項目名稱:canigraduate.uchicago.edu,代碼行數:8,代碼來源:create-mutation-behavior-subject.ts

示例7: ngOnInit

  ngOnInit() {
    const recallSubject$ = new Subject();
    this.time$ = this.store.select("clockReducer");
    this.people$ = this.store.select("peoplezReducer");

    this.person$ = new Subject();
    this.seconds$ = interval(1000);
    this.recall$ = recallSubject$
      .pipe(withLatestFrom(this.time$, (_, y) => y))
      .pipe(map(time => ({type: RECALL, payload: time})));

    this.merged$ = merge(
      this.seconds$.pipe(mapTo({type: SECOND, payload: 1})),
      this.person$.pipe(map(value => ({payload: value, type: ADVANCE}))),
      this.recall$
    );

  }
開發者ID:screenm0nkey,項目名稱:angular2-examples-webpack,代碼行數:18,代碼來源:ngrx-people.component.ts

示例8: test

  test('proxy route responds with `503` if `kbnServer` is not ready yet.', async () => {
    configService.atPath.mockReturnValue(new BehaviorSubject({ autoListen: true }));
    const legacyService = new LegacyService({ env, logger, configService: configService as any });

    const kbnServerListen$ = new Subject();
    MockKbnServer.prototype.listen = jest.fn(() => {
      kbnServerListen$.next();
      return kbnServerListen$.toPromise();
    });

    // Wait until listen is called and proxy route is registered, but don't allow
    // listen to complete and make kbnServer available.
    await legacyService.setup(setupDeps);
    const legacySetupPromise = legacyService.start(startDeps);
    await kbnServerListen$.pipe(first()).toPromise();

    const mockResponse: any = {
      code: jest.fn().mockImplementation(() => mockResponse),
      header: jest.fn().mockImplementation(() => mockResponse),
    };
    const mockResponseToolkit = {
      response: jest.fn().mockReturnValue(mockResponse),
      abandon: Symbol('abandon'),
    };
    const mockRequest = { raw: { req: { a: 1 }, res: { b: 2 } } };

    const [[{ handler }]] = setupDeps.http.server.route.mock.calls;
    const response503 = await handler(mockRequest, mockResponseToolkit);

    expect(response503).toBe(mockResponse);
    expect({
      body: mockResponseToolkit.response.mock.calls,
      code: mockResponse.code.mock.calls,
      header: mockResponse.header.mock.calls,
    }).toMatchSnapshot('503 response');

    // Make sure request hasn't been passed to the legacy platform.
    const [mockedLegacyPlatformProxy] = MockLegacyPlatformProxy.mock.instances;
    expect(mockedLegacyPlatformProxy.emit).not.toHaveBeenCalled();

    // Now wait until kibana is ready and try to request once again.
    kbnServerListen$.complete();
    await legacySetupPromise;
    mockResponseToolkit.response.mockClear();

    const responseProxy = await handler(mockRequest, mockResponseToolkit);
    expect(responseProxy).toBe(mockResponseToolkit.abandon);
    expect(mockResponseToolkit.response).not.toHaveBeenCalled();

    // Make sure request has been passed to the legacy platform.
    expect(mockedLegacyPlatformProxy.emit).toHaveBeenCalledTimes(1);
    expect(mockedLegacyPlatformProxy.emit).toHaveBeenCalledWith(
      'request',
      mockRequest.raw.req,
      mockRequest.raw.res
    );
  });
開發者ID:elastic,項目名稱:kibana,代碼行數:57,代碼來源:legacy_service.test.ts

示例9: ngOnInit

  ngOnInit() {
    this.time$ = this.store.select("clockReducer");
    this.updateHours$ = new Subject();
    this.seconds$ = interval(1000).pipe(mapTo({type: SECOND, payload: 1}));

    this.merged$ = merge(
      this.updateHours$.pipe(map(value => ({type: HOUR, payload: value}))),
      this.seconds$
    );
  }
開發者ID:screenm0nkey,項目名稱:angular2-examples-webpack,代碼行數:10,代碼來源:ngrx-clock-two.component.ts

示例10: constructor

  /**
   *
   * @param period milliseconds
   */
  constructor(
    period?: number, // milliseconds
  ) {
    super(period);

    this.subject = new Subject<T>();
    this.subscription = this.subject.pipe(
      throttle(_ => interval(this.period)),
    ).subscribe((item: T) => super.next(item));
  }
開發者ID:w11k,項目名稱:calendar-for-trello,代碼行數:14,代碼來源:throttle-queue.ts


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