<commit_before>// this module loads the tunes 
//from the JSON file into tuneArray

var Pickin = (function (xhr) {
  'use strict';

  // all the code contained inside this 
  // "function (cb) {..." needs to be inside 
  // the "{ ... }" because otherwise 
  // e.g. the "cb(tuneArray)" call would get executed
  // before the JSON fetch happened. 

  console.log("tuneLoader.js:13; xhr = ", xhr);

  xhr.getAllTunes = function (cb) {

    console.log("tuneLoader.js:17; xhr.getAllTunes = function(cb).  cb = ", cb);
    // an array to hold tunes 
    var tuneArray = [];

    // create a request to retrieve JSON 
    var loader = new XMLHttpRequest();

    // set up loader with callback function
    loader.addEventListener("load", fetchAllTunes);

    // now do the actual load from JSON file
    loader.open("GET", "http://localhost:5000/api/tune");
    loader.send();

    // function to extract tunes from JSON object 
    // and put it into a local (private) array for the callback
    function fetchAllTunes() {

    console.log("tuneLoader.js:35 / inside fetchAllTunes()");

      var jsonObj = JSON.parse(this.responseText);

      var numTunes = jsonObj.length;
      for (var i = 0; i < numTunes; i++) {
        tuneArray.push(jsonObj[i]);
      }

      cb(tuneArray);
    } 
  }

  xhr.getTunesByArtist = function (cb, artistId) {

    console.log("tuneLoader.js:50; xhr.getTunesByArtist = function(cb, artistId).  cb = ", cb);
    console.log("tuneLoader.js:51; this = ", this);

    // an array to hold tunes 
    var tuneArray = [];

    // create a request to retrieve JSON 
    var loader = new XMLHttpRequest();

    // set up loader with callback function
    loader.addEventListener("load", fetchTunesByArtist());

    // now set the path and do the actual load from JSON file
    var path = "http://localhost:5000/api/artist/" + artistId + "/tunes";
    console.log("tuneLoader.js:64 / path = ", path);
    loader.open("GET", path);
    loader.send();

    // function to extract tunes from JSON object 
    // and put it into a local (private) array for the callback
    function fetchTunesByArtist() {

      console.log("tuneLoader.js:72; fetchTunesByArtist; this = ", this);

      var jsonObj = JSON.parse(this.responseText);

      var numTunes = jsonObj.length;
      for (var i = 0; i < numTunes; i++) {
        tuneArray.push(jsonObj[i]);
      }

      cb(tuneArray);<commit_msg>fixed callback to get called at proper time<commit_after>// this module loads the tunes 
//from the JSON file into tuneArray

var Pickin = (function (xhr) {
  'use strict';

  // all the code contained inside this 
  // "function (cb) {..." needs to be inside 
  // the "{ ... }" because otherwise 
  // e.g. the "cb(tuneArray)" call would get executed
  // before the JSON fetch happened. 

  console.log("tuneLoader.js:13; xhr = ", xhr);

  xhr.getAllTunes = function (cb) {

    console.log("tuneLoader.js:17; xhr.getAllTunes = function(cb).  cb = ", cb);
    // an array to hold tunes 
    var tuneArray = [];

    // create a request to retrieve JSON 
    var loader = new XMLHttpRequest();

    // set up loader with callback function
    loader.addEventListener("load", fetchAllTunes);

    // now do the actual load from JSON file
    loader.open("GET", "http://localhost:5000/api/tune");
    loader.send();

    // function to extract tunes from JSON object 
    // and put it into a local (private) array for the callback
    function fetchAllTunes() {

    console.log("tuneLoader.js:35 / inside fetchAllTunes()");

      var jsonObj = JSON.parse(this.responseText);

      var numTunes = jsonObj.length;
      for (var i = 0; i < numTunes; i++) {
        tuneArray.push(jsonObj[i]);
      }

      cb(tuneArray);
    } 
  }

  xhr.getTunesByArtist = function (cb, artistId) {

    console.log("tuneLoader.js:50; xhr.getTunesByArtist = function(cb, artistId).  cb = ", cb);
    console.log("tuneLoader.js:51; this = ", this);

    // an array to hold tunes 
    var tuneArray = [];

    // create a request to retrieve JSON 
    var loader = new XMLHttpRequest();

    // set up loader with callback function
    loader.addEventListener("load", fetchTunesByArtist;

    // now set the path and do the actual load from JSON file
    var path = "http://localhost:5000/api/artist/" + artistId + "/tunes";
    console.log("tuneLoader.js:64 / path = ", path);
    loader.open("GET", path);
    loader.send();

    // function to extract tunes from JSON object 
    // and put it into a local (private) array for the callback
    function fetchTunesByArtist() {

      console.log("tuneLoader.js:72; fetchTunesByArtist; this = ", this);

      var jsonObj = JSON.parse(this.responseText);

      var numTunes = jsonObj.length;
      for (var i = 0; i < numTunes; i++) {
        tuneArray.push(jsonObj[i]);
      }

      cb(tuneArray);
{'fraction_non_alphanumeric': 0.13002266639192253, 'fraction_numerical': 0.00989078920255512, 'mean_word_length': 2.688449848024316, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6560449', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1481, 'n_words': 466}