source: trip-planner-front/node_modules/@angular/material/esm2015/snack-bar/snack-bar-ref.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 11.7 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Subject } from 'rxjs';
9/** Maximum amount of milliseconds that can be passed into setTimeout. */
10const MAX_TIMEOUT = Math.pow(2, 31) - 1;
11/**
12 * Reference to a snack bar dispatched from the snack bar service.
13 */
14export class MatSnackBarRef {
15 constructor(containerInstance, _overlayRef) {
16 this._overlayRef = _overlayRef;
17 /** Subject for notifying the user that the snack bar has been dismissed. */
18 this._afterDismissed = new Subject();
19 /** Subject for notifying the user that the snack bar has opened and appeared. */
20 this._afterOpened = new Subject();
21 /** Subject for notifying the user that the snack bar action was called. */
22 this._onAction = new Subject();
23 /** Whether the snack bar was dismissed using the action button. */
24 this._dismissedByAction = false;
25 this.containerInstance = containerInstance;
26 // Dismiss snackbar on action.
27 this.onAction().subscribe(() => this.dismiss());
28 containerInstance._onExit.subscribe(() => this._finishDismiss());
29 }
30 /** Dismisses the snack bar. */
31 dismiss() {
32 if (!this._afterDismissed.closed) {
33 this.containerInstance.exit();
34 }
35 clearTimeout(this._durationTimeoutId);
36 }
37 /** Marks the snackbar action clicked. */
38 dismissWithAction() {
39 if (!this._onAction.closed) {
40 this._dismissedByAction = true;
41 this._onAction.next();
42 this._onAction.complete();
43 }
44 clearTimeout(this._durationTimeoutId);
45 }
46 /**
47 * Marks the snackbar action clicked.
48 * @deprecated Use `dismissWithAction` instead.
49 * @breaking-change 8.0.0
50 */
51 closeWithAction() {
52 this.dismissWithAction();
53 }
54 /** Dismisses the snack bar after some duration */
55 _dismissAfter(duration) {
56 // Note that we need to cap the duration to the maximum value for setTimeout, because
57 // it'll revert to 1 if somebody passes in something greater (e.g. `Infinity`). See #17234.
58 this._durationTimeoutId = setTimeout(() => this.dismiss(), Math.min(duration, MAX_TIMEOUT));
59 }
60 /** Marks the snackbar as opened */
61 _open() {
62 if (!this._afterOpened.closed) {
63 this._afterOpened.next();
64 this._afterOpened.complete();
65 }
66 }
67 /** Cleans up the DOM after closing. */
68 _finishDismiss() {
69 this._overlayRef.dispose();
70 if (!this._onAction.closed) {
71 this._onAction.complete();
72 }
73 this._afterDismissed.next({ dismissedByAction: this._dismissedByAction });
74 this._afterDismissed.complete();
75 this._dismissedByAction = false;
76 }
77 /** Gets an observable that is notified when the snack bar is finished closing. */
78 afterDismissed() {
79 return this._afterDismissed;
80 }
81 /** Gets an observable that is notified when the snack bar has opened and appeared. */
82 afterOpened() {
83 return this.containerInstance._onEnter;
84 }
85 /** Gets an observable that is notified when the snack bar action is called. */
86 onAction() {
87 return this._onAction;
88 }
89}
90//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic25hY2stYmFyLXJlZi5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9zbmFjay1iYXIvc25hY2stYmFyLXJlZi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFHSCxPQUFPLEVBQWEsT0FBTyxFQUFDLE1BQU0sTUFBTSxDQUFDO0FBVXpDLHlFQUF5RTtBQUN6RSxNQUFNLFdBQVcsR0FBRyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsRUFBRSxFQUFFLENBQUMsR0FBRyxDQUFDLENBQUM7QUFFeEM7O0dBRUc7QUFDSCxNQUFNLE9BQU8sY0FBYztJQTRCekIsWUFBWSxpQkFBcUMsRUFDN0IsV0FBdUI7UUFBdkIsZ0JBQVcsR0FBWCxXQUFXLENBQVk7UUFuQjNDLDRFQUE0RTtRQUMzRCxvQkFBZSxHQUFHLElBQUksT0FBTyxF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