license import { OverlayRef } from '@angular/cdk/overlay' ; import { Observable , Subject } from 'rxjs' ; import { MatSnackBarContainer } from './snack-bar-container' ; /** Event that is emitted when a snack bar is dismissed. */ export interface MatSnackBarDismiss { /** Whether the snack bar was dismissed using the action button. */ dismissedByAction : boolean ; } /**
 * Reference to a snack bar dispatched from the snack bar service.
 */ export class MatSnackBarRef < T > { /** The instance of the component making up the content of the snack bar. */ instance : T ; docs-private containerInstance : MatSnackBarContainer ; /** Subject for notifying the user that the snack bar has been dismissed. */ private readonly _afterDismissed = new Subject < MatSnackBarDismiss > ( ) ; /** Subject for notifying the user that the snack bar has opened and appeared. */ private readonly _afterOpened = new Subject < void > ( ) ; /** Subject for notifying the user that the snack bar action was called. */ private readonly _onAction = new Subject < void > ( ) ; /**
     * Timeout ID for the duration setTimeout call. Used to clear the timeout if the snackbar is
     * dismissed before the duration passes.
     */ private _durationTimeoutId : number ; /** Whether the snack bar was dismissed using the action button. */ private _dismissedByAction = false ; constructor ( containerInstance , private _overlayRef ) { this . containerInstance = containerInstance ; this . onAction ( ) . subscribe ( ( ) => this . dismiss ( ) ) ; containerInstance . _onExit . subscribe ( ( ) => this . _finishDismiss ( ) ) ; } /** Dismisses the snack bar. */ dismiss ( ) { if ( ! this . _afterDismissed . closed ) { this . containerInstance . exit ( ) ; } clearTimeout ( this . _durationTimeoutId ) ; } /** Marks the snackbar action clicked. */ dismissWithAction ( ) { if ( ! this . _onAction . closed ) { this . _dismissedByAction = true ; this . _onAction . next ( ) ; this . _onAction . complete ( ) ; } } deprecated breaking-change closeWithAction ( ) { this . dismissWithAction ( ) ; } /** Dismisses the snack bar after some duration */ _dismissAfter ( duration ) { this . _durationTimeoutId = setTimeout ( ( ) => this . dismiss ( ) , duration ) ; } /** Marks the snackbar as opened */ _open ( ) { if ( ! this . _afterOpened . closed ) { this . _afterOpened . next ( ) ; this . _afterOpened . complete ( ) ; } } /** Cleans up the DOM after closing. */ private _finishDismiss ( ) { this . _overlayRef . dispose ( ) ; if ( ! this . _onAction . closed ) { this . _onAction . complete ( ) ; } this . _afterDismissed . next ( { dismissedByAction : this . _dismissedByAction } ) ; this . _afterDismissed . complete ( ) ; this . _dismissedByAction = false ; } /** Gets an observable that is notified when the snack bar is finished closing. */ afterDismissed ( ) { return this . _afterDismissed . asObservable ( ) ; } /** Gets an observable that is notified when the snack bar has opened and appeared. */ afterOpened ( ) { return this . containerInstance . _onEnter ; } /** Gets an observable that is notified when the snack bar action is called. */ onAction ( ) { return this . _onAction . asObservable ( ) ; } }