<commit_before>'use strict';

import * as Rx from 'rx';
import * as Ix from 'ix';
import * as wx from 'webrx';

import { IRoute } from '../../Routing/RouteManager';
import { ICommandAction, IMenu, IMenuItem } from '../Common/PageHeader/Actions';

import { BaseRoutableViewModel, IBaseRoutableViewModel, IRoutedViewModel } from '../React/BaseRoutableViewModel';
import { SearchViewModel } from '../Common/Search/SearchViewModel';
import { PageHeaderViewModel } from '../Common/PageHeader/PageHeaderViewModel';
import { Default as RoutingMap, IViewModelActivator } from './RoutingMap';

interface IComponentDemoRoutingState {
  route: IRoute;
  componentRoute: string;
  columns: number;
}

export class ComponentDemoViewModel extends BaseRoutableViewModel<IComponentDemoRoutingState> {
  public static displayName = 'ComponentDemoViewModel';

  constructor() {
    super(true);
  }

  public componentRoute: string;

  public columns = wx.property(12);
  public component = wx.property<any>(null);

  private pageHeader: PageHeaderViewModel = null;

  public reRender = wx.command(x => {
    this.navTo(`/demo/${this.componentRoute}?rand=${Math.random()}`);
  });

  componentRouted(pageHeader: PageHeaderViewModel) {
    this.pageHeader = pageHeader;
  }

  getSearch() {
    let viewModel = <IBaseRoutableViewModel>this.component();

    return (viewModel != null && viewModel.getSearch != null) ? viewModel.getSearch() : null;
  }

  getAppMenus() {
    return <IMenu[]>[
      { id: 'demos', header: 'Component Demos', items: RoutingMap.menuItems },
    ];
  }

  getAppActions() {
    return <ICommandAction[]>[
      { id: 'reRender', header: 'Re-Render', command: this.reRender },
    ];
  }

  private getViewModel(componentRoute: string, state: any) {
    let activator: IViewModelActivator = null;

    if (componentRoute != null) {
      this.logger.debug(`Loading View Model for "${componentRoute}"...`);
      activator = RoutingMap.map[componentRoute];

      if (activator == null) {
        let result = Ix.Enumerable
          .fromArray(Object.keys(RoutingMap.map))
          .where(x => x != null && x.length > 0 && x[0] === '^')
          .select(x => ({ path: x, regex: new RegExp(x, 'i') }))
          .select(x => ({ path: x.path, match: x.regex.exec(componentRoute) }))<commit_msg>component demo re-render page header action is now styled as primary (blue)<commit_after>'use strict';

import * as Rx from 'rx';
import * as Ix from 'ix';
import * as wx from 'webrx';

import { IRoute } from '../../Routing/RouteManager';
import { ICommandAction, IMenu, IMenuItem } from '../Common/PageHeader/Actions';

import { BaseRoutableViewModel, IBaseRoutableViewModel, IRoutedViewModel } from '../React/BaseRoutableViewModel';
import { SearchViewModel } from '../Common/Search/SearchViewModel';
import { PageHeaderViewModel } from '../Common/PageHeader/PageHeaderViewModel';
import { Default as RoutingMap, IViewModelActivator } from './RoutingMap';

interface IComponentDemoRoutingState {
  route: IRoute;
  componentRoute: string;
  columns: number;
}

export class ComponentDemoViewModel extends BaseRoutableViewModel<IComponentDemoRoutingState> {
  public static displayName = 'ComponentDemoViewModel';

  constructor() {
    super(true);
  }

  public componentRoute: string;

  public columns = wx.property(12);
  public component = wx.property<any>(null);

  private pageHeader: PageHeaderViewModel = null;

  public reRender = wx.command(x => {
    this.navTo(`/demo/${this.componentRoute}?rand=${Math.random()}`);
  });

  componentRouted(pageHeader: PageHeaderViewModel) {
    this.pageHeader = pageHeader;
  }

  getSearch() {
    let viewModel = <IBaseRoutableViewModel>this.component();

    return (viewModel != null && viewModel.getSearch != null) ? viewModel.getSearch() : null;
  }

  getAppMenus() {
    return <IMenu[]>[
      { id: 'demos', header: 'Component Demos', items: RoutingMap.menuItems },
    ];
  }

  getAppActions() {
    return <ICommandAction[]>[
      { id: 'reRender', header: 'Re-Render', command: this.reRender, bsStyle: 'primary' },
    ];
  }

  private getViewModel(componentRoute: string, state: any) {
    let activator: IViewModelActivator = null;

    if (componentRoute != null) {
      this.logger.debug(`Loading View Model for "${componentRoute}"...`);
      activator = RoutingMap.map[componentRoute];

      if (activator == null) {
        let result = Ix.Enumerable
          .fromArray(Object.keys(RoutingMap.map))
          .where(x => x != null && x.length > 0 && x[0] === '^')
          .select(x => ({ path: x, regex: new RegExp(x, 'i') }))
          .select(x => ({ path: x.path, match: x.regex.exec(componentRoute) }))
{'fraction_non_alphanumeric': 0.1443496801705757, 'fraction_numerical': 0.0017057569296375266, 'mean_word_length': 3.881373569198751, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '5822144', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1391, 'n_words': 337}