<commit_before>var Reflux = require("reflux");
var ImageActions = require("../actions/ImageActions");

var ImageStore = Reflux.createStore({

  listenables: ImageActions,

  _images: [],

  getAll: function() {
    console.log("got all images")
    return this._images;
  },

  getAllImages: function() {
    console.log("get all images");
    var stub = [{_id: "1", url: "https://media.getchute.com/m/12I4gudgjf/c/2500342/500x300"}, {_id: "2", url: "https://media.getchute.com/m/12I4gudgjf/c/2500342/fit/500x300"}];
    // return {
    //   images: stub
    // };
    this._images = stub;
    this.trigger();
    // $.ajax({
    //   type: 'GET',
    //   url: '/images'
    // })
    // .done(function (images) {
    //   this._images = images;
    //   // broadcast that _ideas has changed
    //   this.trigger();
    // }.bind(this))
    // .fail(function(error) {
    //   console.error(error);
    // });
  },<commit_msg>Modify imageStore to handle json data from chute api<commit_after>var Reflux = require("reflux");
var ImageActions = require("../actions/ImageActions");

var ImageStore = Reflux.createStore({

  listenables: ImageActions,

  _images: [],

  getAll: function() {
    console.log("got all images");
    return this._images;
  },

  getAllImages: function() {
    console.log("get all images");
    // var stub = [{_id: "1", url: "https://media.getchute.com/m/12I4gudgjf/c/2500342/500x300"}, {_id: "2", url: "https://media.getchute.com/m/12I4gudgjf/c/2500342/fit/500x300"}];

    // this._images = stub;
    // this.trigger();
    $.ajax({
      type: 'GET',
      url: 'http://getchute.com/v2/albums/aus6kwrg/assets/'
    })
    .done(function (images) {
      var imageData = JSON.parse(images).data;
      console.log("ajax complete2", JSON.parse(images));


      for (var i = 0; i < imageData.length; i++) {
        var imageAttributes = {};
        var currentImageData = imageData[i];
        imageAttributes["id"] = currentImageData.id;
        imageAttributes["url"] = currentImageData.source.source_url;
        imageAttributes["thumbnail"] = currentImageData.thumbnail;
        imageAttributes["caption"] = currentImageData.caption;
        imageAttributes["username"] = currentImageData.username;
        imageAttributes["avatar"] = currentImageData.user.avatar;
        imageAttributes["votes"] = currentImageData.votes;
        imageAttributes["hearts"] = currentImageData.hearts;
        imageAttributes["tags"] = currentImageData.tags;

        this._images.push(imageAttributes);
      }
      console.log("done with for loop", this._images);
      // broadcast that _images has changed
      this.trigger();
    }.bind(this))
    .fail(function(error) {
      console.error(error);
    });
  },
{'fraction_non_alphanumeric': 0.16770186335403728, 'fraction_numerical': 0.026306174643770552, 'mean_word_length': 2.867231638418079, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '4987773', 'n_tokens_mistral': 942, 'n_tokens_neox': 881, 'n_words': 161}