<commit_before>"use strict";

import {ChangeEmitter} from "../utils/ChangeEmitter.js";
import AppDispatcher from "../dispatcher/AppDispatcher";

import NowPlayingConstants from "../constants/NowPlayingConstants.js";
import PlaylistConstants from "../constants/PlaylistConstants.js";
import CursorConstants from "../constants/CursorConstants.js";

import CursorStore from "./CursorStore.js";
import PlaylistStore from "./PlaylistStore.js";

import CtrlConstants from "../constants/ControlConstants.js";


var CONTROL_EVENT = "control";

var currentPlaying = null;
var currentRepeat = null;

function setCurrentTrackSource(source) {
  localStorage.setItem("currentTrackSource", source);
}

function currentTrackSource() {
  var s = localStorage.getItem("currentTrackSource");
  if (s === null) {
    return null;
  }
  return s;
}

function setCurrentTrack(track) {
  localStorage.setItem("currentTrack", JSON.stringify(track));
}

function _playing() {
  var v = localStorage.getItem("playing");
  if (v === null) {
    return false;
  }
  return JSON.parse(v);
}

function _repeat() {
  var v = localStorage.getItem("repeat");
  if (v === null) {
    return false;
  }
  return JSON.parse(v);
}

function playing() {
  if (currentPlaying === null) {
    currentPlaying = _playing();
  }
  return currentPlaying;
}

function repeat() {
  if (currentRepeat === null) {
    currentRepeat = _repeat();
  }
  return currentRepeat;
}

function setPlaying(v) {
  currentPlaying = v;
  localStorage.setItem("playing", JSON.stringify(v));
}

function setRepeat(v) {
  currentRepeat = v;
  localStorage.setItem("repeat", JSON.stringify(v));
}

function currentTrack() {
  var c = localStorage.getItem("currentTrack");
  if (c === null) {
    return null;
  }
  return JSON.parse(c);
}


class NowPlayingStore extends ChangeEmitter {
  getPlaying() {
    return playing();
  }

  getRepeat() {
    return repeat();
  }

  getTrack() {
    return currentTrack();
  }

  getSource() {
    return currentTrackSource();
  }

  emitControl(type, value) {
    this.emit(CONTROL_EVENT, type, value);
  }

  /**
   * @param {function} callback
   */
  addControlListener(callback) {<commit_msg>Cache current track in NowPlayingStore.<commit_after>"use strict";

import {ChangeEmitter} from "../utils/ChangeEmitter.js";
import AppDispatcher from "../dispatcher/AppDispatcher";

import NowPlayingConstants from "../constants/NowPlayingConstants.js";
import PlaylistConstants from "../constants/PlaylistConstants.js";
import CursorConstants from "../constants/CursorConstants.js";

import CursorStore from "./CursorStore.js";
import PlaylistStore from "./PlaylistStore.js";

import CtrlConstants from "../constants/ControlConstants.js";


var CONTROL_EVENT = "control";

var currentPlaying = null;
var currentRepeat = null;
var _currentTrack = null;

function setCurrentTrackSource(source) {
  localStorage.setItem("currentTrackSource", source);
}

function currentTrackSource() {
  var s = localStorage.getItem("currentTrackSource");
  if (s === null) {
    return null;
  }
  return s;
}

function setCurrentTrack(track) {
  localStorage.setItem("currentTrack", JSON.stringify(track));
  _currentTrack = track;
}

function _playing() {
  var v = localStorage.getItem("playing");
  if (v === null) {
    return false;
  }
  return JSON.parse(v);
}

function _repeat() {
  var v = localStorage.getItem("repeat");
  if (v === null) {
    return false;
  }
  return JSON.parse(v);
}

function playing() {
  if (currentPlaying === null) {
    currentPlaying = _playing();
  }
  return currentPlaying;
}

function repeat() {
  if (currentRepeat === null) {
    currentRepeat = _repeat();
  }
  return currentRepeat;
}

function setPlaying(v) {
  currentPlaying = v;
  localStorage.setItem("playing", JSON.stringify(v));
}

function setRepeat(v) {
  currentRepeat = v;
  localStorage.setItem("repeat", JSON.stringify(v));
}

function currentTrack() {
  if (_currentTrack === null) {
    var c = localStorage.getItem("currentTrack");
    if (c === null) {
      return null;
    }
    _currentTrack = JSON.parse(c);
  }
  return _currentTrack;
}


class NowPlayingStore extends ChangeEmitter {
  getPlaying() {
    return playing();
  }

  getRepeat() {
    return repeat();
  }

  getTrack() {
    return currentTrack();
  }

  getSource() {
    return currentTrackSource();
  }

  emitControl(type, value) {
    this.emit(CONTROL_EVENT, type, value);
  }

  /**
   * @param {function} callback
   */
  addControlListener(callback) {
{'fraction_non_alphanumeric': 0.1384820239680426, 'fraction_numerical': 0.0, 'mean_word_length': 4.086907449209932, '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': '5891853', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1385, 'n_words': 322}