<commit_before>'use strict';

import * as wx from 'webrx';

import BaseViewModel from '../../React/BaseViewModel';

export enum DialogResult {
  Accepted,
  Cancelled
}

export interface IValidatable {
  isValid: Rx.Observable<boolean>;
}

export class ModalDialogViewModel extends BaseViewModel {
  public static displayName = 'ModalDialogViewModel';

  constructor(title?: string, public content?: IValidatable | any) {
    super();

    if (String.isNullOrEmpty(title) === false) {
      this.title(title);
    }
  }

  public title = wx.property('');
  public cancelText = wx.property('Cancel');
  public acceptText = wx.property('Accept');

  public accept = wx.asyncCommand(this.getCanAccept(), x => Rx.Observable.return(DialogResult.Accepted));
  public cancel = wx.asyncCommand(x => Rx.Observable.return(DialogResult.Cancelled));
  public reset = wx.asyncCommand(x => Rx.Observable.return(null));

  public result = Rx.Observable
    .merge(this.accept.results, this.cancel.results)
    .take(1)
    .toProperty();

  private getCanAccept() {
    let validatable = this.content as IValidatable;

    return validatable.isValid == null ? Rx.Observable.return(true) : validatable.isValid;<commit_msg>fixing modal dialog so that reset now functions properly (re-usable modal dialog components)<commit_after>'use strict';

import * as wx from 'webrx';

import BaseViewModel from '../../React/BaseViewModel';

export enum DialogResult {
  Accepted,
  Cancelled
}

export interface IValidatable {
  isValid: Rx.Observable<boolean>;
}

export class ModalDialogViewModel extends BaseViewModel {
  public static displayName = 'ModalDialogViewModel';

  constructor(title?: string, public content?: IValidatable | any) {
    super();

    if (String.isNullOrEmpty(title) === false) {
      this.title(title);
    }
  }

  public title = wx.property('');
  public cancelText = wx.property('Cancel');
  public acceptText = wx.property('Accept');

  public accept = wx.asyncCommand(this.getCanAccept(), x => Rx.Observable.return(DialogResult.Accepted));
  public cancel = wx.asyncCommand(x => Rx.Observable.return(DialogResult.Cancelled));
  public reset = wx.asyncCommand(x => Rx.Observable.return(null));

  public result = Rx.Observable
    .merge(this.accept.results, this.cancel.results, this.reset.results)
    .toProperty();

  private getCanAccept() {
    let validatable = this.content as IValidatable;

    return validatable.isValid == null ? Rx.Observable.return(true) : validatable.isValid;
{'fraction_non_alphanumeric': 0.12610088070456366, 'fraction_numerical': 0.00040032025620496394, 'mean_word_length': 4.420824295010846, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5104609', 'n_tokens_mistral': 756, 'n_tokens_neox': 724, 'n_words': 175}