<commit_before>import {
  ChangeDetectionStrategy,
  Component,
  EventEmitter,
  Input,
} from '@angular/core';

import {
  isObservable,
  isSubject,
  isLargeArray,
} from '../../utils';

const defaultExpansionDepth = 1;

@Component({
  selector: 'bt-render-state',
  template: require('./render-state.html'),
})
export class RenderState {
  @Input() id: string;
  @Input() path: Array<string | number>;
  @Input() level: number;
  @Input() state;

  private expansionState = {};

  private get none() {
    return this.state == null || Object.keys(this.state).length === 0;
  }

  private nest(key: string): boolean {
    return typeof this.state[key] === 'object';
  }

  private expanded(key: string): boolean {
    if (this.expansionState.hasOwnProperty(key)) {
      return this.expansionState[key];
    }
    if (isObservable(this.state[key])) { // do not expand observables (default)
      return false;
    }
    if (isLargeArray(this.state[key])) { // same for large arrays which take a long time to render
      return false;
    }
    return this.level <= defaultExpansionDepth; // default depth
  }

  expandTree(key, $event) {
    this.expansionState[key] = !this.expansionState[key];

    $event.preventDefault();
    $event.stopPropagation();
  }

  displayType(d: any): string {
    if (Array.isArray(d)) {
      return `Array[${d.length}]`;
    }
    else if (typeof d === 'object') {
      if (d) {
        if (isSubject(d)) {
          return 'Subject';
        }
        else if (isObservable(d)) {
          return 'Observable';
        }
        return 'Object';
      } else if (d === null) {
        return 'null';
      } else if (d === undefined) {
        return 'undefined';
      }
    }
    return typeof d;
  }

  keys(obj): string[] {
    return (obj instanceof Object) ? Object.keys(obj) : [];
  }
}
<commit_msg>Display the state editor tree collapsed by default. (#611)<commit_after>import {
  ChangeDetectionStrategy,
  Component,
  EventEmitter,
  Input,
} from '@angular/core';

import {
  isObservable,
  isSubject,
  isLargeArray,
} from '../../utils';

@Component({
  selector: 'bt-render-state',
  template: require('./render-state.html'),
})
export class RenderState {
  @Input() id: string;
  @Input() path: Array<string | number>;
  @Input() level: number;
  @Input() state;

  private expansionState = {};

  private get none() {
    return this.state == null || Object.keys(this.state).length === 0;
  }

  private nest(key: string): boolean {
    return typeof this.state[key] === 'object';
  }

  private expanded(key: string): boolean {
    if (this.expansionState.hasOwnProperty(key)) {
      return this.expansionState[key];
    }

    return false;
  }

  expandTree(key, $event) {
    this.expansionState[key] = !this.expansionState[key];

    $event.preventDefault();
    $event.stopPropagation();
  }

  displayType(d: any): string {
    if (Array.isArray(d)) {
      return `Array[${d.length}]`;
    }
    else if (typeof d === 'object') {
      if (d) {
        if (isSubject(d)) {
          return 'Subject';
        }
        else if (isObservable(d)) {
          return 'Observable';
        }
        return 'Object';
      } else if (d === null) {
        return 'null';
      } else if (d === undefined) {
        return 'undefined';
      }
    }
    return typeof d;
  }

  keys(obj): string[] {
    return (obj instanceof Object) ? Object.keys(obj) : [];
  }
}

{'fraction_non_alphanumeric': 0.1553935860058309, 'fraction_numerical': 0.001749271137026239, 'mean_word_length': 2.689247311827957, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '5826354', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1086, 'n_words': 266}