<commit_before>import mitt from 'mitt';

export default (e = []) => {
  const timeline = mitt();
  let lastTime;
  let lastIndex;
  let events;

  Object.assign(timeline, {
    add(event) {
      timeline.push(event);
      timeline.sort((a, b) => a.time - b.time);
    },

    remove(event) {
      const index = timeline.indexOf(event);
      if (index !== -1) {
        timeline.splice(index, 1);
      }
    },

    replace(newEvents) {
      events = newEvents.slice(0);
      events.sort((a, b) => a.time - b.time);
    },

    tick(time = 0) {
      if (time === lastTime) return;

      // If we went back in time, reset the timeline:
      // TODO: should we reset to the last event after the new time?
      if ((lastTime !== undefined && time < lastTime) || !lastIndex) {
        lastIndex = 0;
        lastTime = null;
      }

      for (let i = (lastIndex || 0); i < events.length; i++) {
        const event = events[i];
        if (time > event.time) {
          timeline.emit(event.name, event);
<commit_msg>also emit event when event time === time<commit_after>import mitt from 'mitt';

export default (e = []) => {
  const timeline = mitt();
  let lastTime;
  let lastIndex;
  let events;

  Object.assign(timeline, {
    add(event) {
      timeline.push(event);
      timeline.sort((a, b) => a.time - b.time);
    },

    remove(event) {
      const index = timeline.indexOf(event);
      if (index !== -1) {
        timeline.splice(index, 1);
      }
    },

    replace(newEvents) {
      events = newEvents.slice(0);
      events.sort((a, b) => a.time - b.time);
    },

    tick(time = 0) {
      if (time === lastTime) return;

      // If we went back in time, reset the timeline:
      // TODO: should we reset to the last event after the new time?
      if ((lastTime !== undefined && time < lastTime) || !lastIndex) {
        lastIndex = 0;
        lastTime = null;
      }

      for (let i = (lastIndex || 0); i < events.length; i++) {
        const event = events[i];
        if (time >= event.time) {
          timeline.emit(event.name, event);

{'fraction_non_alphanumeric': 0.1530317613089509, 'fraction_numerical': 0.005774783445620789, 'mean_word_length': 2.1310240963855422, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '6497032', 'n_tokens_mistral': 692, 'n_tokens_neox': 665, 'n_words': 190}