<commit_before>import _ from 'lodash';

import LinearEasing from './easings/Linear.es6';
import * as time from './time.es6';


const fixedMethod = () => {};

export default class Animation {

  constructor({
    from,
    to,
    animationTime = 1000,
    easing = new LinearEasing() }) {
    this.from = from;
    this.to = to;
    this.easing = easing;
    this.animationTime = animationTime;

    this.propsToAnimate = _.intersection(Object.keys(from), Object.keys(to))
                            .filter(property => typeof from[property] === 'number' &&
                                                typeof to[property] === 'number');

    // use the fixed method to avoid undefined checking
    this.onUpdateCallback = fixedMethod;
    this.onStartCallback = fixedMethod;
    this.onStopCallback = fixedMethod;

    this.update = this.update.bind(this);
  }

  onStart(callback) {
    this.onStartCallback = callback;
  }

  onUpdate(callback) {
    this.onUpdateCallback = callback;
  }

  onStop(callback) {
    this.onStopCallback = callback;
  }

  start() {
    this.animationInProgress = true;
    this.progress = 0;
    time.start();

    this.update(0);
  }

  update(highResTimestamp) {
    if (!this.animationInProgress) {
      return;
    }

    requestAnimationFrame(this.update);

    time.update(highResTimestamp);

    this.progress += time.getDeltaTime() * (this.animationTime / 1000); // ms -> s

    // clamp the progress between 0 and 1
    if (this.progress >= 1) {
      this.stop();
      this.progress = 1;
    }

    this.onUpdateCallback(this.easing.getValueForProgress(this.progress));
  }

  stop() {
    this.animationInProgress = false;
  }
}<commit_msg>call start and stop<commit_after>import _ from 'lodash';

import LinearEasing from './easings/Linear.es6';
import * as time from './time.es6';


const fixedMethod = () => {};

export default class Animation {

  constructor({
    from,
    to,
    animationTime = 1000,
    easing = new LinearEasing() }) {
    this.from = from;
    this.to = to;
    this.easing = easing;
    this.animationTime = animationTime;

    this.propsToAnimate = _.intersection(Object.keys(from), Object.keys(to))
                            .filter(property => typeof from[property] === 'number' &&
                                                typeof to[property] === 'number');

    // use the fixed method to avoid undefined checking
    this.onUpdateCallback = fixedMethod;
    this.onStartCallback = fixedMethod;
    this.onStopCallback = fixedMethod;

    this.update = this.update.bind(this);
  }

  onStart(callback) {
    this.onStartCallback = callback;
  }

  onUpdate(callback) {
    this.onUpdateCallback = callback;
  }

  onStop(callback) {
    this.onStopCallback = callback;
  }

  start() {
    this.onStartCallback();

    this.animationInProgress = true;
    this.progress = 0;
    time.start();

    this.update(0);
  }

  update(highResTimestamp) {
    if (!this.animationInProgress) {
      return;
    }

    requestAnimationFrame(this.update);

    time.update(highResTimestamp);

    this.progress += time.getDeltaTime() * (this.animationTime / 1000); // ms -> s
    this.progress = Math.min(this.progress, 1); // [0, 1]

    this.onUpdateCallback(this.easing.getValueForProgress(this.progress));

    if (this.progress === 1) {
      this.stop();
    }
  }

  stop() {
    this.animationInProgress = false;

    this.onStopCallback();
  }
}
{'fraction_non_alphanumeric': 0.12881651642919453, 'fraction_numerical': 0.009305030532131433, 'mean_word_length': 2.5610766045548656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4580108', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1016, 'n_words': 211}