Beispiel #1
0
  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'));
      });
  });
 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);
     });
 }
Beispiel #3
0
  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);
  });
 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}))
   );
 }
  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];
      }));
  }
Beispiel #6
0
 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)
     )
 })
const epic3: Epic<FluxStandardAction> = action$ =>
  action$.pipe(
    ofType('THIRD'),
    mapTo({
      type: 'third'
    })
  );
  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();
  }
Beispiel #9
0
 function addHandler(h: any) {
   timer(50, 20, rxTestScheduler).pipe(
     mapTo('ev'),
     take(2),
     concat(NEVER)
   ).subscribe(h);
 }
  "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$;
}