<commit_before>import {
  AfterViewInit,
  Component,
  ElementRef,
  HostBinding,
  OnDestroy,
  Renderer2,
  ViewEncapsulation
} from '@angular/core';
import { MDCSnackbarAdapter } from './snackbar-adapter';
import { isBrowser } from '../common/platform';

const { MDCSnackbarFoundation } = require('@material/snackbar');
const { getCorrectEventName } = require('@material/animation');

type UnlistenerMap = WeakMap<EventListener, Function>;

@Component({
  selector: 'mdc-snackbar',
  template:
  `
  <div class="mdc-snackbar__text">{{message}}</div>
  <div class="mdc-snackbar__action-wrapper">
    <button type="button" class="mdc-button mdc-snackbar__action-button" aria-hidden>{{actionText}}</button>
  </div>
  `,
  encapsulation: ViewEncapsulation.None
})
export class SnackbarComponent implements AfterViewInit, OnDestroy {
  @Input() alignStart: boolean;
  private message: string;
  private actionText: string;
  @HostBinding('class.mdc-snackbar') isHostClass = true;
  @HostBinding('attr.aria-live') ariaLive: string = 'assertive';
  @HostBinding('attr.aria-atomic') ariaAtomic: string = 'true';
  @HostBinding('attr.aria-hidden') ariaHidden: string = 'true';
  @HostBinding('class.mdc-snackbar--align-start') get classAlignStart(): string {
    return this.alignStart ? 'mdc-snackbar--align-start' : '';
  }

  private _unlisteners: Map<string, UnlistenerMap> = new Map<string, UnlistenerMap>();

  private _mdcAdapter: MDCSnackbarAdapter = {
    addClass: (className: string) => {
      const { _renderer: renderer, _root: root } = this;
      renderer.addClass(root.nativeElement, className);
    },
    removeClass: (className: string) => {
      const { _renderer: renderer, _root: root } = this;
      renderer.removeClass(root.nativeElement, className);
    },
    setAriaHidden: () => {
      const { _renderer: renderer, _root: root } = this;
      renderer.setAttribute(root.nativeElement, 'aria-hidden', 'true');
    },
    unsetAriaHidden: () => {
      const { _renderer: renderer, _root: root } = this;
      renderer.removeAttribute(root.nativeElement, 'aria-hidden');
    },
    setMessageText: (message: string) => {
      this.message = message;
    },
    setActionText: (actionText: string) => {
      this.actionText = actionText;
    },
    setActionAriaHidden: () => {
      const { _renderer: renderer, _root: root } = this;
      renderer.setAttribute(root.nativeElement.querySelector(MDCSnackbarFoundation.strings.ACTION_BUTTON_SELECTOR), 'aria-hidden', 'true');
    },
    unsetActionAriaHidden: () => {
      const { _renderer: renderer, _root: root } = this;
      renderer.removeAttribute(root.nativeElement.querySelector(MDCSnackbarFoundation.strings.ACTION_BUTTON_SELECTOR), 'aria-hidden');
    },
    registerActionClickHandler: (handler: EventListener) => {
      if (this._root) {
        this.listen_('click', handler);
      }
    },
    deregisterActionClickHandler: (handler: EventListener) => {
      this.unlisten_('click', handler);
    },
    registerTransitionEndHandler: (handler: EventListener) => {
      if (this._root && isBrowser()) {
        this.listen_(getCorrectEventName(window, 'transitionend'), handler);
      }
    },
    deregisterTransitionEndHandler: (handler: EventListener) => {
      if (isBrowser()) {
        this.unlisten_(getCorrectEventName(window, 'transitionend'), handler);
      }
    }
  };

  private _foundation: {
    init: Function,
    destroy: Function,
    show: Function,
    setDismissOnAction: Function
  } = new MDCSnackbarFoundation(this._mdcAdapter);

  constructor(
    private _renderer: Renderer2,
    private _root: ElementRef) { }

  ngAfterViewInit() {
    this._foundation.init();
  }
  ngOnDestroy() {
    this._foundation.destroy();
  }

  show(data: any, dismissOnAction: boolean = true) {
    this._foundation.setDismissOnAction(dismissOnAction);
    this._foundation.show(data);
  }

  listen_(type: string, listener: EventListener, ref: ElementRef = this._root) {
    if (!this._unlisteners.has(type)) {
      this._unlisteners.set(type, new WeakMap<EventListener, Function>());
    }
    const unlistener = this._renderer.listen(ref.nativeElement, type, listener);
    this._unlisteners.get(type).set(listener, unlistener);
  }

  unlisten_(type: string, listener: EventListener) {
    if (!this._unlisteners.has(type)) {
      return;
    }
    const unlisteners = this._unlisteners.get(type);
    if (!unlisteners.has(listener)) {
      return;
    }
    unlisteners.get(listener)();
    unlisteners.delete(listener);
  }
}<commit_msg>feat(snackbar): Add [dismissOnAction] boolean input<commit_after>import {
  AfterViewInit,
  Component,
  ElementRef,
  HostBinding,
  OnDestroy,
  Renderer2,
  ViewEncapsulation
} from '@angular/core';
import { MDCSnackbarAdapter } from './snackbar-adapter';
import { isBrowser } from '../common/platform';

const { MDCSnackbarFoundation } = require('@material/snackbar');
const { getCorrectEventName } = require('@material/animation');

type UnlistenerMap = WeakMap<EventListener, Function>;

@Component({
  selector: 'mdc-snackbar',
  template:
  `
  <div class="mdc-snackbar__text">{{message}}</div>
  <div class="mdc-snackbar__action-wrapper">
    <button type="button" class="mdc-button mdc-snackbar__action-button" aria-hidden>{{actionText}}</button>
  </div>
  `,
  encapsulation: ViewEncapsulation.None
})
export class SnackbarComponent implements AfterViewInit, OnDestroy {
  @Input() alignStart: boolean;
  @Input()
  get dismissOnAction() { return this._foundation.dismissesOnAction(); }
  set dismissOnAction(value) {
    this._foundation.setDismissOnAction(value);
  }
  private message: string;
  private actionText: string;
  @HostBinding('class.mdc-snackbar') isHostClass = true;
  @HostBinding('attr.aria-live') ariaLive: string = 'assertive';
  @HostBinding('attr.aria-atomic') ariaAtomic: string = 'true';
  @HostBinding('attr.aria-hidden') ariaHidden: string = 'true';
  @HostBinding('class.mdc-snackbar--align-start') get classAlignStart(): string {
    return this.alignStart ? 'mdc-snackbar--align-start' : '';
  }

  private _unlisteners: Map<string, UnlistenerMap> = new Map<string, UnlistenerMap>();

  private _mdcAdapter: MDCSnackbarAdapter = {
    addClass: (className: string) => {
      const { _renderer: renderer, _root: root } = this;
      renderer.addClass(root.nativeElement, className);
    },
    removeClass: (className: string) => {
      const { _renderer: renderer, _root: root } = this;
      renderer.removeClass(root.nativeElement, className);
    },
    setAriaHidden: () => {
      const { _renderer: renderer, _root: root } = this;
      renderer.setAttribute(root.nativeElement, 'aria-hidden', 'true');
    },
    unsetAriaHidden: () => {
      const { _renderer: renderer, _root: root } = this;
      renderer.removeAttribute(root.nativeElement, 'aria-hidden');
    },
    setMessageText: (message: string) => {
      this.message = message;
    },
    setActionText: (actionText: string) => {
      this.actionText = actionText;
    },
    setActionAriaHidden: () => {
      const { _renderer: renderer, _root: root } = this;
      renderer.setAttribute(root.nativeElement.querySelector(MDCSnackbarFoundation.strings.ACTION_BUTTON_SELECTOR), 'aria-hidden', 'true');
    },
    unsetActionAriaHidden: () => {
      const { _renderer: renderer, _root: root } = this;
      renderer.removeAttribute(root.nativeElement.querySelector(MDCSnackbarFoundation.strings.ACTION_BUTTON_SELECTOR), 'aria-hidden');
    },
    registerActionClickHandler: (handler: EventListener) => {
      if (this._root) {
        this.listen_('click', handler);
      }
    },
    deregisterActionClickHandler: (handler: EventListener) => {
      this.unlisten_('click', handler);
    },
    registerTransitionEndHandler: (handler: EventListener) => {
      if (this._root && isBrowser()) {
        this.listen_(getCorrectEventName(window, 'transitionend'), handler);
      }
    },
    deregisterTransitionEndHandler: (handler: EventListener) => {
      if (isBrowser()) {
        this.unlisten_(getCorrectEventName(window, 'transitionend'), handler);
      }
    }
  };

  private _foundation: {
    init: Function,
    destroy: Function,
    show: Function,
    setDismissOnAction: Function
  } = new MDCSnackbarFoundation(this._mdcAdapter);

  constructor(
    private _renderer: Renderer2,
    private _root: ElementRef) { }

  ngAfterViewInit() {
    this._foundation.init();
  }
  ngOnDestroy() {
    this._foundation.destroy();
  }

  show(data: any, dismissOnAction: boolean = true) {
    this._foundation.setDismissOnAction(dismissOnAction);
    this._foundation.show(data);
  }

  listen_(type: string, listener: EventListener, ref: ElementRef = this._root) {
    if (!this._unlisteners.has(type)) {
      this._unlisteners.set(type, new WeakMap<EventListener, Function>());
    }
    const unlistener = this._renderer.listen(ref.nativeElement, type, listener);
    this._unlisteners.get(type).set(listener, unlistener);
  }

  unlisten_(type: string, listener: EventListener) {
    if (!this._unlisteners.has(type)) {
      return;
    }
    const unlisteners = this._unlisteners.get(type);
    if (!unlisteners.has(listener)) {
      return;
    }
    unlisteners.get(listener)();
    unlisteners.delete(listener);
  }
}
{'fraction_non_alphanumeric': 0.13900526372327854, 'fraction_numerical': 0.0004296916962079708, 'mean_word_length': 3.965333333333333, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4137764', 'n_tokens_mistral': 2907, 'n_tokens_neox': 2893, 'n_words': 522}