Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Last active December 25, 2019 20:54
Show Gist options
  • Save alexytiger/df1249e7afe1412e6a20fc07dbabed4a to your computer and use it in GitHub Desktop.
Save alexytiger/df1249e7afe1412e6a20fc07dbabed4a to your computer and use it in GitHub Desktop.
e-book
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { tap, map } from 'rxjs/operators';
import { SnackBarActions } from '../actions';
import { MatSnackBar } from '@angular/material';
import { SnackBarComponent } from '../../components/snackbar/snack-bar.component';
@Injectable()
export class SnackBarEffects {
static readonly SNACKBAR_DELAY: number = 6000;
constructor(private readonly actions$: Actions, private matSnackBar: MatSnackBar) {}
openSnackbar$ = createEffect(
() =>
this.actions$.pipe(
ofType(SnackBarActions.open),
map(action => action.payload),
tap(payload => this.matSnackBar.openFromComponent(SnackBarComponent, {
data: payload,
duration: SnackBarEffects.SNACKBAR_DELAY }))
),
{ dispatch: false }
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment