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


TypeScript operators.mapTo函數代碼示例

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


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

示例1: it

  it('should raises error when promise rejects', (done: MochaDone) => {
    const e1 = concat(
      of(1),
      timer(10).pipe(mapTo(2)),
      timer(10).pipe(mapTo(3)),
      timer(100).pipe(mapTo(4))
    );
    const expected = [1, 2];
    const error = new Error('error');

    e1.pipe(
      debounce((x: number) => {
        if (x === 3) {
          return new Promise((resolve: any, reject: any) => { reject(error); });
        } else {
          return new Promise((resolve: any) => { resolve(42); });
        }
      })
    ).subscribe((x: number) => {
      expect(x).to.equal(expected.shift()); },
      (err: any) => {
        expect(err).to.be.an('error', 'error');
        expect(expected.length).to.equal(0);
        done();
      }, () => {
        done(new Error('should not be called'));
      });
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:28,代碼來源:debounce-spec.ts

示例2: sample3

 sample3() {
   const listener = merge(
     fromEvent(document, 'mousedown').pipe(mapTo(false)),
     fromEvent(document, 'mousemove').pipe(mapTo(true))
   )
     .pipe(sample(fromEvent(document, 'mouseup')))
     .subscribe(isDragging => {
       console.log('Were you dragging?', isDragging);
     });
 }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:10,代碼來源:filtering.service.ts

示例3: it

  it('should map twice', () => {
    const a = hot('-0----1-^-2---3--4-5--6--7-8-|');
    const asubs =         '^                    !';
    const expected =      '--h---h--h-h--h--h-h-|';

    const r = a.pipe(
      mapTo(-1),
      mapTo('h')
    );

    expectObservable(r).toBe(expected);
    expectSubscriptions(a.subscriptions).toBe(asubs);
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:13,代碼來源:mapTo-spec.ts

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

示例5: constructor

  constructor(private socket$: Socket) {
    const disconnect$ = this.socket$.fromEvent("disconnect");
    const connect$ = this.socket$.fromEvent("connect");
    this.connected$ = merge(connect$.pipe(mapTo(true)), disconnect$.pipe(mapTo(false)));

    this.message$ = this.socket$
      .fromEvent("msg")
      .pipe(map((data: SocketMessage) => data.msg));

    this.messages$ = this.message$
      .pipe(startWith([]))
      .pipe(scan((acc: string[], curr: string) => {
        return [...acc, curr];
      }));
  }
開發者ID:screenm0nkey,項目名稱:angular2-examples-webpack,代碼行數:15,代碼來源:chat.service.ts

示例6: switchMap

 switchMap(ok => {
     if (!ok) {
         return [false]
     }
     return mutateGraphQL(
         gql`
             mutation DeleteRegistryExtension($extension: ID!) {
                 extensionRegistry {
                     deleteExtension(extension: $extension) {
                         alwaysNil
                     }
                 }
             }
         `,
         { extension }
     ).pipe(
         map(({ data, errors }) => {
             if (
                 !data ||
                 !data.extensionRegistry ||
                 !data.extensionRegistry.deleteExtension ||
                 (errors && errors.length > 0)
             ) {
                 throw createAggregateError(errors)
             }
         }),
         mapTo(true)
     )
 })
開發者ID:JoYiRis,項目名稱:sourcegraph,代碼行數:29,代碼來源:backend.ts

示例7: ofType

const epic3: Epic<FluxStandardAction> = action$ =>
  action$.pipe(
    ofType('THIRD'),
    mapTo({
      type: 'third'
    })
  );
開發者ID:redux-observable,項目名稱:redux-observable,代碼行數:7,代碼來源:typings.ts

示例8: multicast1

  multicast1() {
    // emit every 2 seconds, take 5
    const source = interval(2000).pipe(take(5));

    const example = source.pipe(
      // since we are multicasting below, side effects will be executed once
      tap(() => console.log('Side Effect #1')),
      mapTo('Result!')
    );

    // subscribe subject to source upon connect()
    const multi = example.pipe(multicast(() => new Subject())) as ConnectableObservable<string>;
    /*
      subscribers will share source
      output:
      "Side Effect #1"
      "Result!"
      "Result!"
      ...
    */
    const subscriberOne = multi.subscribe(val => console.log(val));
    const subscriberTwo = multi.subscribe(val => console.log(val));
    // subscribe subject to source
    multi.connect();
  }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:25,代碼來源:connectable.service.ts

示例9: addHandler

 function addHandler(h: any) {
   timer(50, 20, rxTestScheduler).pipe(
     mapTo('ev'),
     take(2),
     concat(NEVER)
   ).subscribe(h);
 }
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:7,代碼來源:fromEventPattern-spec.ts

示例10: canPlay

  "loaded"; // loaded without autoplay enabled

/**
 * Emit once a "can-play" message as soon as the clock$ anounce that the content
 * can begin to be played.
 *
 * Warn you if the metadata is not yet loaded metadata by emitting a
 * "not-loaded-metadata" message first.
 * @param {Observable} clock$
 * @returns {Observable}
 */
function canPlay(
  clock$ : Observable<IInitClockTick>,
  mediaElement : HTMLMediaElement
) : Observable<"can-play"|"not-loaded-metadata"> {
  const isLoaded$ = clock$.pipe(
    filter((tick) => {
      const { seeking, stalled, readyState, currentRange } = tick;
      return !seeking &&
        stalled == null &&
        (readyState === 4 || readyState === 3 && currentRange != null) &&
        (!shouldValidateMetadata() || mediaElement.duration > 0);
    }),
    take(1),
    mapTo("can-play" as "can-play")
  );

  if (shouldValidateMetadata() && mediaElement.duration === 0) {
    return observableConcat(
      observableOf("not-loaded-metadata" as "not-loaded-metadata"),
      isLoaded$
    );
  }

  return isLoaded$;
}
開發者ID:canalplus,項目名稱:rx-player,代碼行數:36,代碼來源:initial_seek_and_play.ts


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