<commit_before>import {
  AfterContentInit,
  AfterViewInit,
  Component,
  ElementRef,
  Input,
  OnChanges,
  OnDestroy,
  OnInit,
  SimpleChanges
} from '@angular/core';
import { ISuperTableColumn, ColumnState, ISuperTableOptions } from './interfaces';
import { SuperTableState } from './SuperTableState';
import { Subscription } from 'rxjs/Subscription';

@Component({
  selector: 'super-table',
  template: `
    <super-table-head [tableClasses]="tableClasses"></super-table-head>

    <super-table-body
      *ngIf="isReady"
      [rows]="filteredSortedRows"
      [tableClasses]="tableClasses"
      [options]="options"
      [style.height]="bodyHeight + 'px'"
      [bodyHeight]="bodyHeight">
    </super-table-body>

    <div
      class="loading-message"
      *ngIf="!isReady && !hasError">
      Loading...
    </div>

    <div *ngIf="hasError">An error occurred.</div>
  `,
  styles: [`
    :host {
      position: relative;
      display: block;
    }
    .loading-message {
      text-align: center;
    }
  `],
  providers: [SuperTableState]
})
export class SuperTable implements AfterContentInit, OnChanges, OnDestroy, OnInit {

  // inputs
  @Input() rows: Array<any>;
  @Input() columns: Array<ISuperTableColumn>;
  @Input() options: ISuperTableOptions;
  @Input() tableClasses: any;

  // properties
  isReady = false;
  hasError = false;
  bodyHeight: number;
  filteredSortedRows: Array<any>;
  private subscription: Subscription;

  constructor (private el: ElementRef, private state: SuperTableState) {}

  ngOnInit(): void {
    this.subscription = this.state.stateChanged$.subscribe(() => this.sortAndFilterRows());
  }

  ngAfterContentInit(): void {
    if (this.options.autoHeight) {
      const parentHeight: number = this.el.nativeElement.parentElement.clientHeight;
      this.setTableHeight(parentHeight);
    }
    this.isReady = true;
  }

  ngOnChanges(changes: SimpleChanges): void {
    // Inform state of columns changes
    if (changes['columns'].isFirstChange()) {
      this.state.setColumns(changes['columns'].currentValue);
    }
    this.sortAndFilterRows();
  }

  ngOnDestroy(): void {
    this.subscription.unsubscribe();
  }<commit_msg>fix(super-table-component): Fix issue with async changes<commit_after>import {
  AfterContentInit,
  AfterViewInit,
  Component,
  ElementRef,
  Input,
  OnChanges,
  OnDestroy,
  OnInit,
  SimpleChanges
} from '@angular/core';
import { ISuperTableColumn, ColumnState, ISuperTableOptions } from './interfaces';
import { SuperTableState } from './SuperTableState';
import { Subscription } from 'rxjs/Subscription';

@Component({
  selector: 'super-table',
  template: `
    <super-table-head [tableClasses]="tableClasses"></super-table-head>

    <super-table-body
      *ngIf="isReady"
      [rows]="filteredSortedRows"
      [tableClasses]="tableClasses"
      [options]="options"
      [style.height]="bodyHeight + 'px'"
      [bodyHeight]="bodyHeight">
    </super-table-body>

    <div
      class="loading-message"
      *ngIf="!isReady && !hasError">
      Loading...
    </div>

    <div *ngIf="hasError">An error occurred.</div>
  `,
  styles: [`
    :host {
      position: relative;
      display: block;
    }
    .loading-message {
      text-align: center;
    }
  `],
  providers: [SuperTableState]
})
export class SuperTable implements AfterContentInit, OnChanges, OnDestroy, OnInit {

  // inputs
  @Input() rows: Array<any>;
  @Input() columns: Array<ISuperTableColumn>;
  @Input() options: ISuperTableOptions;
  @Input() tableClasses: any;

  // properties
  isReady = false;
  hasError = false;
  bodyHeight: number;
  filteredSortedRows: Array<any>;
  private subscription: Subscription;

  constructor (private el: ElementRef, private state: SuperTableState) {}

  ngOnInit(): void {
    this.subscription = this.state.stateChanged$.subscribe(() => this.sortAndFilterRows());
  }

  ngAfterContentInit(): void {
    if (this.options.autoHeight) {
      const parentHeight: number = this.el.nativeElement.parentElement.clientHeight;
      this.setTableHeight(parentHeight);
    }
    this.isReady = true;
  }

  ngOnChanges(changes: SimpleChanges): void {
    // Inform state of columns changes
    if (changes['columns'] && changes['columns'].isFirstChange()) {
      this.state.setColumns(changes['columns'].currentValue);
    }
    this.sortAndFilterRows();
  }

  ngOnDestroy(): void {
    this.subscription.unsubscribe();
  }
{'fraction_non_alphanumeric': 0.1391206313416009, 'fraction_numerical': 0.0, 'mean_word_length': 3.620833333333333, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, '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': '904708', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1348, 'n_words': 272}