<commit_before>import React from 'react';

import GifPlayer from './GifPlayer';

const preload = (src, callback) => {
  var img = new Image();
  if (typeof callback === 'function') {
    img.onload = () => callback(img);
  }
  img.src = src;
};

const firstGifFrameUrl = img => {
  const canvas = document.createElement('canvas');
  if (typeof canvas.getContext !== 'function') {
    return null;
  }
  canvas.width = img.width;
  canvas.height = img.height;
  const ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return canvas.toDataURL();
}

class GifPlayerContainer extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      playing: false,
      gif: props.gif,
      still: props.still
    };
    this.updateId = -1;
  }

  componentDidMount () {
    this.updateImages(this.props);
  }

  componentWillReceiveProps (nextProps) {
    this.updateImages(nextProps, this.props);
  }

  updateImages (newProps, oldProps = {}) {
    const oldGif = oldProps.gif;
    const newGif = newProps.gif;
    const oldStill = oldProps.still;
    const newStill = newProps.still;
    if (oldGif === newGif && oldStill === newStill) {
      return;
    }

    const updateId = ++this.updateId;
    this.setState({
      gif: newGif,
      still: newStill
    });

    if (newGif && oldGif !== newGif) {
      preload(newGif, img => {
        if (!newStill && this.updateId === updateId) {
          const still = firstGifFrameUrl(img);
          if (still) {
            this.setState({ still });
          }
        }
      });
    }
    if (newStill && newStill !== oldStill) {
      preload(newStill);<commit_msg>Tiny refactor: 'newStill !== oldStill' <> 'oldStill !== newStill'.<commit_after>import React from 'react';

import GifPlayer from './GifPlayer';

const preload = (src, callback) => {
  var img = new Image();
  if (typeof callback === 'function') {
    img.onload = () => callback(img);
  }
  img.src = src;
};

const firstGifFrameUrl = img => {
  const canvas = document.createElement('canvas');
  if (typeof canvas.getContext !== 'function') {
    return null;
  }
  canvas.width = img.width;
  canvas.height = img.height;
  const ctx = canvas.getContext('2d');
  ctx.drawImage(img, 0, 0);
  return canvas.toDataURL();
}

class GifPlayerContainer extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      playing: false,
      gif: props.gif,
      still: props.still
    };
    this.updateId = -1;
  }

  componentDidMount () {
    this.updateImages(this.props);
  }

  componentWillReceiveProps (nextProps) {
    this.updateImages(nextProps, this.props);
  }

  updateImages (newProps, oldProps = {}) {
    const oldGif = oldProps.gif;
    const newGif = newProps.gif;
    const oldStill = oldProps.still;
    const newStill = newProps.still;
    if (oldGif === newGif && oldStill === newStill) {
      return;
    }

    const updateId = ++this.updateId;
    this.setState({
      gif: newGif,
      still: newStill
    });

    if (newGif && oldGif !== newGif) {
      preload(newGif, img => {
        if (!newStill && this.updateId === updateId) {
          const still = firstGifFrameUrl(img);
          if (still) {
            this.setState({ still });
          }
        }
      });
    }
    if (newStill && oldStill !== newStill) {
      preload(newStill);
{'fraction_non_alphanumeric': 0.14485842026825632, 'fraction_numerical': 0.002384500745156483, 'mean_word_length': 2.632034632034632, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, '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': '2676290', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1087, 'n_words': 246}