<commit_before>import Ticker from "../utils/Ticker.js";

export default class LoopElement extends HTMLElement {
  constructor({autoplay = true, background = false} = {}) {
    super();
    this._autoplay = autoplay;
    this._background = background;
  }

  connectedCallback() {
    if(!this._background) {
      window.addEventListener("blur", this._pauseBinded = this.pause.bind(this));
      window.addEventListener("focus", this._playBinded = this.play.bind(this));
    }
    if(this._autoplay) {
      this.play();
    }
  }

  disconnectedCallback() {
    this.pause();
    window.removeEventListener("blur", this._pauseBinded);
    window.removeEventListener("focus", this._playBinded);
  }

  play() {
    Ticker.add(this._updateBinded = this._updateBinded || this.update.bind(this));
    this.dispatchEvent(new Event("playing"));
  }

  pause() {
    Ticker.delete(this._updateBinded);
    this.dispatchEvent(new Event("pause"));
  }

  update() {}
}

window.customElements.define("dlib-loop", LoopElement);<commit_msg>clean LoopElement<commit_after>import Ticker from "../utils/Ticker.js";

export default class LoopElement extends HTMLElement {
  constructor({autoplay = true, background = false} = {}) {
    super();
    this._autoplay = autoplay || this.hasAttribute("autoplay");
    this._background = background || this.hasAttribute("background");

    this.paused = true;

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

  connectedCallback() {
    if(!this._background) {
      window.addEventListener("blur", this._pauseBinded = this.pause.bind(this));
      window.addEventListener("focus", this._playBinded = this.play.bind(this));
    }
    if(this._autoplay) {
      this.play();
    }
  }

  disconnectedCallback() {
    this.pause();
    window.removeEventListener("blur", this._pauseBinded);
    window.removeEventListener("focus", this._playBinded);
  }

  play() {
    this.paused = false;
    Ticker.add(this._updateBinded);
    this.dispatchEvent(new Event("playing"));
  }

  pause() {
    this.paused = true;
    Ticker.delete(this._updateBinded);
    this.dispatchEvent(new Event("pause"));
  }

  update() {}
}

window.customElements.define("dlib-loop", LoopElement);
{'fraction_non_alphanumeric': 0.15314907113729043, 'fraction_numerical': 0.0, 'mean_word_length': 3.789587852494577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5603205', 'n_tokens_mistral': 696, 'n_tokens_neox': 673, 'n_words': 104}