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