<commit_before>import React from 'react';
import Main from './components/main.js';
import TestRunner from './test-runner/runner';
import ShortcutProcessor from './keyboard-shortcut/shortcut-processor';
import Editor from './editor';

export default class MainController {

  constructor(domNode, config) {
    this._domNode = domNode;
    this._config = config;
  }


  render() {
    this._editorDomNodeId = 'editorId';
    this._runnerDomNodeId = 'runnerId';
    this._render();
    this._editor = new Editor(this._editorDomNodeId);
    this._runner = new TestRunner(document.getElementById(this._runnerDomNodeId));
    this._runner.render(this._config.iframeSrcUrl);
    this.setEditorContent('');
    this._registerShortcuts(this._config.shortcuts);
  }

  _render(shortcuts=[]) {
    var props = {
      metaKeySymbol: '⌘',
      editorId: this._editorDomNodeId,
      runnerId: this._runnerDomNodeId,
      onSave: this.onSave.bind(this),
      onResetCode: this._onResetCode,
      shortcuts: shortcuts,
      es6Katas: this._es6Katas || null
    };
    React.render(<Main {...props}/>, document.querySelector('#tddbin'));
  }

  showEs6KatasNavigation(es6KataData) {
    this._es6Katas = es6KataData;
    this._render();
    this._editor.resize(); // adding the katas navigation changes the space ACE can use, we must inform it to resize :/
  }

  onSave() {
    window.localStorage.setItem('code', this._editor.getContent());
    this.runEditorContent();
  }

  _onResetCode() {
    window.localStorage.removeItem('code');
    window.location.reload();
  }

  setEditorContent(sourceCode) {
    this._editor.setContent(sourceCode);
  }

  runEditorContent() {
    this._runner.send(this._editor.getContent());
  }

  _registerShortcuts(shortcuts) {
    var processor = new ShortcutProcessor();
    processor.registerShortcuts(shortcuts);
    processor.onKeyDown(this._updateOverlayView.bind(this));
    processor.onShortcutEnd(this._hideOverlayView.bind(this));
  }

  _hideOverlayView() {
    this._render([]);
  }

  _updateOverlayView(pressedKeys) {
    var allShortcuts = this._config.shortcuts;
    var applicableShortcuts = allShortcuts.filter(function(shortcut) {
      return shortcut.isStartOfKeyCombo(pressedKeys);<commit_msg>Fix #10, prevent to fail when storing in localStorage fails.<commit_after>import React from 'react';
import Main from './components/main.js';
import TestRunner from './test-runner/runner';
import ShortcutProcessor from './keyboard-shortcut/shortcut-processor';
import Editor from './editor';

export default class MainController {

  constructor(domNode, config) {
    this._domNode = domNode;
    this._config = config;
  }


  render() {
    this._editorDomNodeId = 'editorId';
    this._runnerDomNodeId = 'runnerId';
    this._render();
    this._editor = new Editor(this._editorDomNodeId);
    this._runner = new TestRunner(document.getElementById(this._runnerDomNodeId));
    this._runner.render(this._config.iframeSrcUrl);
    this.setEditorContent('');
    this._registerShortcuts(this._config.shortcuts);
  }

  _render(shortcuts=[]) {
    var props = {
      metaKeySymbol: '⌘',
      editorId: this._editorDomNodeId,
      runnerId: this._runnerDomNodeId,
      onSave: this.onSave.bind(this),
      onResetCode: this._onResetCode,
      shortcuts: shortcuts,
      es6Katas: this._es6Katas || null
    };
    React.render(<Main {...props}/>, document.querySelector('#tddbin'));
  }

  showEs6KatasNavigation(es6KataData) {
    this._es6Katas = es6KataData;
    this._render();
    this._editor.resize(); // adding the katas navigation changes the space ACE can use, we must inform it to resize :/
  }

  onSave() {
    try {
      window.localStorage.setItem('code', this._editor.getContent());
    } catch (e) {
    }
    this.runEditorContent();
  }

  _onResetCode() {
    window.localStorage.removeItem('code');
    window.location.reload();
  }

  setEditorContent(sourceCode) {
    this._editor.setContent(sourceCode);
  }

  runEditorContent() {
    this._runner.send(this._editor.getContent());
  }

  _registerShortcuts(shortcuts) {
    var processor = new ShortcutProcessor();
    processor.registerShortcuts(shortcuts);
    processor.onKeyDown(this._updateOverlayView.bind(this));
    processor.onShortcutEnd(this._hideOverlayView.bind(this));
  }

  _hideOverlayView() {
    this._render([]);
  }

  _updateOverlayView(pressedKeys) {
    var allShortcuts = this._config.shortcuts;
    var applicableShortcuts = allShortcuts.filter(function(shortcut) {
      return shortcut.isStartOfKeyCombo(pressedKeys);
{'fraction_non_alphanumeric': 0.1274874261972447, 'fraction_numerical': 0.003061447627378089, 'mean_word_length': 3.8763326226012795, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6850557', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1399, 'n_words': 245}