<commit_before>import { Directive, Inject, ElementRef, OnInit } from '@angular/core';
import { AnimationService } from './animation.service';
import { AnimationBuilder } from '../builder';
import { AnimationOptions } from '../contracts';

@Directive({
  selector: '[animates]',
  exportAs: 'animates',
  inputs: [
    'animates',
    'animatesOnInit'
  ]
})
export class AnimatesDirective implements OnInit {
  private _defaultOptions: AnimationOptions;
  private _initOptions: AnimationOptions;

  private _animationBuilder: AnimationBuilder;

  set animates(options: AnimationOptions) {
    this._defaultOptions = options;
  }

  set animatesOnInit(options: AnimationOptions) {
    this._initOptions = options;
  }

  get animationBuilder(): AnimationBuilder {
    return this._animationBuilder;
  }

  constructor( @Inject(ElementRef) private _elementRef: ElementRef, @Inject(AnimationService) animationService: AnimationService) {
    this._animationBuilder = animationService.builder();
  }

  public ngOnInit() {
    if (!this._initOptions) {
      return;
    }

    this._animationBuilder
      .setOptions(this._initOptions)
      .show(this._elementRef.nativeElement)
      .then((element: HTMLElement) => element, (error: string) => {
        // Animation interrupted
      });
  }

  public start(options?: AnimationOptions): Promise<HTMLElement> {
    this.setOptions(options);

    return this._animationBuilder
      .animate(this._elementRef.nativeElement)
      .then((element: HTMLElement) => element, (error: string) => {
        // Animation interrupted
      });
  }

  public hide(options?: AnimationOptions): Promise<HTMLElement> {
    this.setOptions(options);

    return this._animationBuilder
      .setOptions(options)
      .hide(this._elementRef.nativeElement)
      .then((element: HTMLElement) => element, (error: string) => {
        // Animation interrupted
      });
  }

  public show(options?: AnimationOptions): Promise<HTMLElement> {
    this.setOptions(options);

    return this._animationBuilder
      .show(this._elementRef.nativeElement)
      .then((element: HTMLElement) => element, (error: string) => {
        // Animation interrupted<commit_msg>Added option to use show or hide on init with the Angular2 directive, where animate stays the default.<commit_after>import { Directive, Inject, ElementRef, OnInit } from '@angular/core';
import { AnimationService } from './animation.service';
import { AnimationBuilder } from '../builder';
import { AnimationOptions } from '../contracts';

@Directive({
  selector: '[animates]',
  exportAs: 'animates',
  inputs: [
    'animates',
    'animatesOnInit',
    'animatesInitMode',
  ],
})
export class AnimatesDirective implements OnInit {
  private _defaultOptions: AnimationOptions;
  private _initOptions: AnimationOptions;
  private _initMode: string;

  private _animationBuilder: AnimationBuilder;

  set animates(options: AnimationOptions) {
    this._defaultOptions = options;
  }

  set animatesOnInit(options: AnimationOptions) {
    this._initOptions = options;
  }

  set animatesInitMode(mode: string) {
    if (typeof mode === 'string') {
      this._initMode = mode.toLowerCase();
    }
  }

  get animationBuilder(): AnimationBuilder {
    return this._animationBuilder;
  }

  constructor( @Inject(ElementRef) private _elementRef: ElementRef, @Inject(AnimationService) animationService: AnimationService) {
    this._animationBuilder = animationService.builder();
  }

  public ngOnInit() {
    if (!this._initOptions) {
      return;
    }

    let promise: Promise<HTMLElement>;
    let builder = this._animationBuilder
      .setOptions(this._initOptions);

    switch (this._initMode) {
      case 'show':
        promise = builder.show(this._elementRef.nativeElement);
        break;
      case 'hide':
        promise = builder.hide(this._elementRef.nativeElement);
        break;
      default:
        promise = builder.animate(this._elementRef.nativeElement);
    }

    promise.then((element: HTMLElement) => element, (error: string) => {
      // Animation interrupted
    });
  }

  public start(options?: AnimationOptions): Promise<HTMLElement> {
    this.setOptions(options);

    return this._animationBuilder
      .animate(this._elementRef.nativeElement)
      .then((element: HTMLElement) => element, (error: string) => {
        // Animation interrupted
      });
  }

  public hide(options?: AnimationOptions): Promise<HTMLElement> {
    this.setOptions(options);

    return this._animationBuilder
      .setOptions(options)
      .hide(this._elementRef.nativeElement)
      .then((element: HTMLElement) => element, (error: string) => {
        // Animation interrupted
      });
  }

  public show(options?: AnimationOptions): Promise<HTMLElement> {
    this.setOptions(options);

    return this._animationBuilder
      .show(this._elementRef.nativeElement)
      .then((element: HTMLElement) => element, (error: string) => {
        // Animation interrupted
{'fraction_non_alphanumeric': 0.11808340016038492, 'fraction_numerical': 0.00020048115477145148, 'mean_word_length': 3.623725671918443, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 26, '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': '7241129', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1367, 'n_words': 302}