Last active
December 25, 2019 20:54
-
-
Save alexytiger/df1249e7afe1412e6a20fc07dbabed4a to your computer and use it in GitHub Desktop.
e-book
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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