<commit_before>import React from 'react';
import { render } from 'react-dom';

import { PropTypes, Router, Route, IndexRoute } from 'react-router';

// Views
import Map from './views/Map';
import About from './views/About';

import ServerSelection from './views/ServerSelection';
import PipBoy from './views/PipBoy';

import {
  connection,
  status,
} from 'pipboylib';

const styles = {
  app: {
    display: 'flex',
    flexDirection: 'row',
    flexWrap: 'no-wrap',
    alignItems: 'stretch',
    height: '100%',
    width: '100%',
  },
};

const {
  discover,
  createSocket,
  sendPeriodicHeartbeat,
  createConnectionSubject,
} = connection;

const {
  connected,
} = status;

import {
  toType,
} from './constants/server_types';

import dispatcher from './dispatcher';

export default class App extends React.Component {
  static displayName = 'PipBoyApp';

  static propTypes = {
    children: React.PropTypes.node,
    history: React.PropTypes.object,
  }

  static childContextTypes = {
    sendCommand: React.PropTypes.func.isRequired,
  }

  constructor(props) {
    super(props);
  }

  getChildContext = () => ({
    sendCommand: this.sendCommand,
  })

  componentWillMount() {
    discover()
      .then(server => createSocket(server.info.address))
      .then(socket => {
        this.cancelHeartbeat = sendPeriodicHeartbeat(socket);
        this.connection = createConnectionSubject(socket);
        this.subscription = this.connection.subscribe(x => {
          dispatcher.dispatch({
            type: toType(x.type),
            payload: x.payload,
          });
        });

        return connected(this.connection);
      })
      .then(() => {
        this.props.history.pushState(null, '/pipboy/about');

        // Get initial LocalMap state
        this.sendCommand('RequestLocalMapSnapshot');
      })
      .catch(err => {
        throw err;
      });
  }

  sendCommand = (type, ...args) => {
    if (this.connection) {
      this.connection.onNext([type, ...args]);
    }
  }

  render() {
    return (<commit_msg>Redirect to the server selection on error.<commit_after>import React from 'react';
import { render } from 'react-dom';

import { PropTypes, Router, Route, IndexRoute } from 'react-router';

// Views
import Map from './views/Map';
import About from './views/About';

import ServerSelection from './views/ServerSelection';
import PipBoy from './views/PipBoy';

import {
  connection,
  status,
} from 'pipboylib';

const styles = {
  app: {
    display: 'flex',
    flexDirection: 'row',
    flexWrap: 'no-wrap',
    alignItems: 'stretch',
    height: '100%',
    width: '100%',
  },
};

const {
  discover,
  createSocket,
  sendPeriodicHeartbeat,
  createConnectionSubject,
} = connection;

const {
  connected,
} = status;

import {
  toType,
} from './constants/server_types';

import dispatcher from './dispatcher';

export default class App extends React.Component {
  static displayName = 'PipBoyApp';

  static propTypes = {
    children: React.PropTypes.node,
    history: React.PropTypes.object,
  }

  static childContextTypes = {
    sendCommand: React.PropTypes.func.isRequired,
  }

  constructor(props) {
    super(props);
  }

  getChildContext = () => ({
    sendCommand: this.sendCommand,
  })

  componentWillMount() {
    discover()
      .then(server => createSocket(server.info.address))
      .then(socket => {
        // Redirect to server selection on disconnect (for now).
        // Since close always follows an emitted 'error' on socket, we'll only
        // redirect in close.
        socket.on('close', (hadError) => {
          if (hadError) {
            console.error('Connection to Fallout 4 server had an error. Redirecting to server selection screen.');
          }
          this.props.history.pushState(null, '/');
        });
        socket.on('timeout', () => {
          console.error('Fallout 4 timed out.');
          socket.destroy();
        });
        socket.setTimeout(2000);

        this.cancelHeartbeat = sendPeriodicHeartbeat(socket);
        this.connection = createConnectionSubject(socket);
        this.subscription = this.connection.subscribe(x => {
          dispatcher.dispatch({
            type: toType(x.type),
            payload: x.payload,
          });
        });

        return connected(this.connection);
      })
      .then(() => {
        this.props.history.pushState(null, '/pipboy/about');

        // Get initial LocalMap state
        this.sendCommand('RequestLocalMapSnapshot');
      })
      .catch(err => {
        throw err;
      });
  }

  sendCommand = (type, ...args) => {
    if (this.connection) {
      this.connection.onNext([type, ...args]);
    }
  }

  render() {
    return (
{'fraction_non_alphanumeric': 0.13910093299406276, 'fraction_numerical': 0.003816793893129771, 'mean_word_length': 2.600763358778626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4170654', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1388, 'n_words': 315}