<commit_before>import { ApplicationEvent } from 'snjs';
import { WebApplication } from '@/ui_models/application';

export type CtrlState = Partial<Record<string, any>>
export type CtrlProps = Partial<Record<string, any>>

export class PureViewCtrl {
  $timeout: ng.ITimeoutService
  /** Passed through templates */
  application!: WebApplication
  props: CtrlProps = {}
  state: CtrlState = {}
  private unsubApp: any
  private unsubState: any
  private stateTimeout: any

  /* @ngInject */
  constructor($timeout: ng.ITimeoutService) {
    this.$timeout = $timeout;
  }

  $onInit() {
    this.state = {
      ...this.getInitialState(),
      ...this.state,
    }
    this.addAppEventObserver();
    this.addAppStateObserver();
  }

  deinit() {
    this.unsubApp();
    this.unsubState();
    this.unsubApp = undefined;
    this.unsubState = undefined;
    (this.application as any) = undefined;
    if (this.stateTimeout) {
      this.$timeout.cancel(this.stateTimeout);
    }
  }

  $onDestroy() {
    this.deinit();
  }

  public get appState() {
    return this.application!.getAppState();
  }

  /** @private */
  async resetState() {
    this.state = this.getInitialState();
    await this.setState(this.state);
  }

  /** @override */
  getInitialState() {<commit_msg>fix: keep application reference when on pure view controller destruction<commit_after>import { ApplicationEvent } from 'snjs';
import { WebApplication } from '@/ui_models/application';

export type CtrlState = Partial<Record<string, any>>
export type CtrlProps = Partial<Record<string, any>>

export class PureViewCtrl {
  $timeout: ng.ITimeoutService
  /** Passed through templates */
  application!: WebApplication
  props: CtrlProps = {}
  state: CtrlState = {}
  private unsubApp: any
  private unsubState: any
  private stateTimeout: any

  /* @ngInject */
  constructor($timeout: ng.ITimeoutService) {
    this.$timeout = $timeout;
  }

  $onInit() {
    this.state = {
      ...this.getInitialState(),
      ...this.state,
    }
    this.addAppEventObserver();
    this.addAppStateObserver();
  }

  deinit() {
    this.unsubApp();
    this.unsubState();
    this.unsubApp = undefined;
    this.unsubState = undefined;
    if (this.stateTimeout) {
      this.$timeout.cancel(this.stateTimeout);
    }
  }

  $onDestroy() {
    this.deinit();
  }

  public get appState() {
    return this.application!.getAppState();
  }

  /** @private */
  async resetState() {
    this.state = this.getInitialState();
    await this.setState(this.state);
  }

  /** @override */
  getInitialState() {
{'fraction_non_alphanumeric': 0.13852140077821012, 'fraction_numerical': 0.0, 'mean_word_length': 3.256622516556291, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '252252', 'n_tokens_mistral': 817, 'n_tokens_neox': 796, 'n_words': 169}