// I get called once when the component is being mounted.
	public ngOnInit() : void {

		this.parentParamMapSubscription = this.activatedRoute.parent.paramMap
			// TIMING HACK: We need to add a tick-delay between the root ParamMap emit
			// and the callback in order to fix several Angular bugs.
			.pipe( delay( 10 ) )
			.subscribe(
				( paramMap: ParamMap ) : void => {

					this.loadData( +paramMap.get( "id" ) );

				}
			)
		;

		this.paramMapSubscription = this.activatedRoute.paramMap
			// TIMING HACK: We need to add a tick-delay between the root ParamMap emit
			// and the callback in order to fix several Angular bugs.
			.pipe( delay( 10 ) )
			.subscribe(
			( paramMap: ParamMap ) : void => {

					this.filterText = ( paramMap.get( "filterText" ) || "" );
					this.filterType = ( paramMap.get( "filterType" ) || "active" );
					this.applyFilterToList();

				}
			)
		;

	}
Ejemplo n.º 2
0
 .and.callFake(function (params: RequestQueryParams) {
   if (params && params.get('username')) {
     return of(mockData2).pipe(delay(0));
   } else {
     if (params.get('page') === '1') {
       mockData.data = mockItems.slice(0, 15);
     } else {
       mockData.data = mockItems.slice(15, 18);
     }
     return of(mockData).pipe(delay(0));
   }
 });
Ejemplo n.º 3
0
 race2() {
   // Throws an error and ignores the other observables.
   const first = of('first').pipe(
     delay(100),
     map(_ => {
       throw 'error';
     })
   );
   const second = of('second').pipe(delay(200));
   const third = of('third').pipe(delay(300));
   //  nothing logged
   race(first, second, third).subscribe(val => console.log(val));
 }
Ejemplo n.º 4
0
 zip1() {
   const sourceOne = of('Hello');
   const sourceTwo = of('World!');
   const sourceThree = of('Goodbye');
   const sourceFour = of('World!');
   // wait until all observables have emitted a value then emit all as an array
   const example = zip(
     sourceOne,
     sourceTwo.pipe(delay(1000)),
     sourceThree.pipe(delay(2000)),
     sourceFour.pipe(delay(3000))
   );
   // output: ["Hello", "World!", "Goodbye", "World!"]
   const subscribe = example.subscribe(val => console.log(val));
 }
Ejemplo n.º 5
0
 getPeople(term: string = null): Observable<Person[]> {
     let items = getMockPeople();
     if (term) {
         items = items.filter(x => x.name.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1);
     }
     return of(items).pipe(delay(500));
 }
Ejemplo n.º 6
0
  exhaustMap1() {
    const sourceInterval = interval(1000);
    const delayedInterval = sourceInterval.pipe(delay(10), take(4));

    const exhaustSub = merge(
      //  delay 10ms, then start interval emitting 4 values
      delayedInterval,
      //  emit immediately
      of(true)
    )
      .pipe(exhaustMap(_ => sourceInterval.pipe(take(5))))
      /*
       *  The first emitted value (of(true)) will be mapped
       *  to an interval observable emitting 1 value every
       *  second, completing after 5.
       *  Because the emissions from the delayed interval
       *  fall while this observable is still active they will be ignored.
       *
       *  Contrast this with concatMap which would queue,
       *  switchMap which would switch to a new inner observable each emission,
       *  and mergeMap which would maintain a new subscription for each emitted value.
       */
      //  output: 0, 1, 2, 3, 4
      .subscribe(val => console.log(val));
  }
Ejemplo n.º 7
0
export function fromRef<T>(ref: DatabaseQuery, event: ListenEvent, listenType = 'on'): Observable<AngularFireAction<DatabaseSnapshot<T>>> {
  return new Observable<SnapshotPrevKey<T>>(subscriber => {
    const fn = ref[listenType](event, (snapshot, prevKey) => {
      subscriber.next({ snapshot, prevKey });
      if (listenType == 'once') { subscriber.complete(); }
    }, subscriber.error.bind(subscriber));
    if (listenType == 'on') {
      return { unsubscribe() { ref.off(event, fn)} };
    } else {
      return { unsubscribe() { } };
    }
  }).pipe(
    map(payload =>  {
      const { snapshot, prevKey } = payload;
      let key: string | null = null;
      if (snapshot.exists()) { key = snapshot.key; }
      return { type: event, payload: snapshot, prevKey, key };
    }),
    // Ensures subscribe on observable is async. This handles
    // a quirk in the SDK where on/once callbacks can happen
    // synchronously.
    delay(0),
    share()
  );
}
Ejemplo n.º 8
0
 getAll(): Observable<Article[]> {
   return this.apiService.get('articles')
     .pipe(
       delay(1000),
       map(data => data)
     );
 }
Ejemplo n.º 9
0
            mergeMap(({ payload: { notification } }: ITriggerNotificationAction) => {
                if (notification.ttl === undefined) return EMPTY

                return of(closeNotification(notification.id)).pipe(
                    delay(notification.ttl)
                )
            })
Ejemplo n.º 10
0
const errorHandlingEpics = action$ =>
  action$.pipe(
    ofType(ERROR),
    delay(3000),
    take(1),
    map(stopError)
  );