Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Created February 8, 2020 04:55
Show Gist options
  • Save alexytiger/74016754667f965f88a0e345d6a82be9 to your computer and use it in GitHub Desktop.
Save alexytiger/74016754667f965f88a0e345d6a82be9 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import { createEffect } from '@ngrx/effects';
import { tap, map } from 'rxjs/operators';
import * as fromStore from '../reducers';
import { Store, select } from '@ngrx/store';
import { SpinnerOverlayService } from '../../services/spinner-overlay.service';
@Injectable()
export class SpinnerEffects {
constructor(
private store$: Store<fromStore.AppState>,
private spinner: SpinnerOverlayService) {}
handleSpinner$ = createEffect(
() =>
this.store$.pipe(
select(fromStore.getSpinnerShow),
tap( isShow =>
isShow ? this.spinner.show() : this.spinner.hide()
)),
{ dispatch: false }
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment