<commit_before>import React from 'react';
import ColorPicker from 'rc-color-picker';
import Canvas from './Canvas';
import fetchJson from '../util/fetch-json';
import Slider from 'material-ui/Slider';
import Snackbar from 'material-ui/Snackbar';

class Room extends React.Component {
  static loadProps({ params, loadContext }, cb) {
    const apiBaseUrl = (loadContext || window).apiBaseUrl;

    fetchJson(`${apiBaseUrl}/api/rooms/${params.id}`)
    .then((res) => {
      cb(null, {
        id: res.room.id,
        name: res.room.name,
        strokes: res.room.strokes,
        width: res.room.canvas_width,
        height: res.room.canvas_height,
        watcherCount: res.room.watcher_count,
        csrfToken: (loadContext || window).csrfToken,
      });
    })
    .catch((err) => {
      cb(err);
    });
  }

  constructor(props) {
    super(props);
    this.state = {
      strokes: props.strokes,
      tmpStroke: null,
      strokeWidth: 20,
      red: 128,
      green: 128,
      blue: 128,
      alpha: 0.7,
      watcherCount: props.watcherCount,
      showError: false,
      errorMessage: '',
    };
  }

  componentDidMount() {
    const token = this.props.csrfToken;
    this.eventSource = new EventSource(`/api/strokes/rooms/${this.props.id}?csrf_token=${token}`);
    this.eventSource.addEventListener('stroke', (ev) => {
      if (ev.data) {
        const strokes = this.state.strokes;
        const stroke = JSON.parse(ev.data);
        const isNew = !strokes.some((s) => s.id === stroke.id);
        if (isNew) {
          this.setState({ strokes: strokes.concat([stroke]).sort((a, b) => b.id - a.id) });
        }
      }
    });
    this.eventSource.addEventListener('error', (ev) => {
      if (ev.data) {
        this.setState({
          showError: true,
          errorMessage: ev.data,
        });
        this.eventSource.close();
      }
    });
    this.eventSource.addEventListener('watcher_count', (ev) => {
      if (ev.data) {
        this.setState({
          watcherCount: parseInt(ev.data),
        });
      }
    });
  }

  componentWillUnmount() {<commit_msg>ev.data is compulsory<commit_after>import React from 'react';
import ColorPicker from 'rc-color-picker';
import Canvas from './Canvas';
import fetchJson from '../util/fetch-json';
import Slider from 'material-ui/Slider';
import Snackbar from 'material-ui/Snackbar';

class Room extends React.Component {
  static loadProps({ params, loadContext }, cb) {
    const apiBaseUrl = (loadContext || window).apiBaseUrl;

    fetchJson(`${apiBaseUrl}/api/rooms/${params.id}`)
    .then((res) => {
      cb(null, {
        id: res.room.id,
        name: res.room.name,
        strokes: res.room.strokes,
        width: res.room.canvas_width,
        height: res.room.canvas_height,
        watcherCount: res.room.watcher_count,
        csrfToken: (loadContext || window).csrfToken,
      });
    })
    .catch((err) => {
      cb(err);
    });
  }

  constructor(props) {
    super(props);
    this.state = {
      strokes: props.strokes,
      tmpStroke: null,
      strokeWidth: 20,
      red: 128,
      green: 128,
      blue: 128,
      alpha: 0.7,
      watcherCount: props.watcherCount,
      showError: false,
      errorMessage: '',
    };
  }

  componentDidMount() {
    const token = this.props.csrfToken;
    this.eventSource = new EventSource(`/api/strokes/rooms/${this.props.id}?csrf_token=${token}`);
    this.eventSource.addEventListener('stroke', (ev) => {
      const strokes = this.state.strokes;
      const stroke = JSON.parse(ev.data);
      const isNew = !strokes.some((s) => s.id === stroke.id);
      if (isNew) {
        this.setState({ strokes: strokes.concat([stroke]).sort((a, b) => b.id - a.id) });
      }
    });
    this.eventSource.addEventListener('error', (ev) => {
      this.setState({
        showError: true,
        errorMessage: ev.data,
      });
      this.eventSource.close();
    });
    this.eventSource.addEventListener('watcher_count', (ev) => {
      this.setState({
        watcherCount: parseInt(ev.data),
      });
    });
  }

  componentWillUnmount() {
{'fraction_non_alphanumeric': 0.15688185140073083, 'fraction_numerical': 0.00633373934226553, 'mean_word_length': 2.4591406908171862, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4647744', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1320, 'n_words': 250}