<commit_before>
let Fluxxor = require('fluxxor');
let _       = require('lodash');

let CartStore = Fluxxor.createStore({

  initialize: function() {
    this.loading = false;
    this.error = null;
    this.items = {};

    this.bindActions(
      'cart_add_item', this.onAddItem,
      'cart_remove_item', this.onRemoveItem,
      'cart_update_qty', this.onUpdateQty
    );
  },

  getQty: function() {
    var items = _.values(this.items);
    return items
      .map((item) => item.qty)
      .reduce((pre, cur) => pre + cur, 0);
  },

  getSubTotal: function() {
    let items = _.values(this.items);
    return items
      .map((item) => item.qty * item.price)
      .reduce((pre, cur) => pre + cur, 0);
  },

  onAddItem: function(item) {
    if(!this.items[item.id]) {
      this.items[item.id] = item;
    }

    if(!this.items[item.id].qty) {
      this.items[item.id].qty = 0;
    }

    this.items[item.id].qty += 1;
    this.emit('change');
  },

  onRemoveItem: function(id) {
    this.items[id].qty -= 1;
    if(this.items[id].qty === 0) {
      delete this.items[id];
    }
    this.emit('change');
  },

  onUpdateQty: function({ id, qty }) {
    this.items[id].qty = qty;
    if(this.items[id].qty === 0) {
      delete this.items[id];
    }
    this.emit('change');
  },

  getState: function() {
    return {
      items: this.items,
      qty: this.getQty(),
      subtotal: this.getSubTotal()
    };
  }

});

module.exports = CartStore;<commit_msg>Changed cart store method to remove item<commit_after>
let Fluxxor = require('fluxxor');
let _       = require('lodash');

let CartStore = Fluxxor.createStore({

  initialize: function() {
    this.loading = false;
    this.error = null;
    this.items = {};

    this.bindActions(
      'cart_add_item', this.onAddItem,
      'cart_remove_item', this.onRemoveItem,
      'cart_update_qty', this.onUpdateQty
    );
  },

  getQty: function() {
    var items = _.values(this.items);
    return items
      .map((item) => item.qty)
      .reduce((pre, cur) => pre + cur, 0);
  },

  getSubTotal: function() {
    let items = _.values(this.items);
    return items
      .map((item) => item.qty * item.price)
      .reduce((pre, cur) => pre + cur, 0);
  },

  onAddItem: function(item) {
    if(!this.items[item.id]) {
      this.items[item.id] = item;
    }

    if(!this.items[item.id].qty) {
      this.items[item.id].qty = 0;
    }

    this.items[item.id].qty += 1;
    this.emit('change');
  },

  onRemoveItem: function(id) {
    delete this.items[id];
    this.emit('change');
  },

  onUpdateQty: function({ id, qty }) {
    this.items[id].qty = qty;
    if(this.items[id].qty === 0) {
      delete this.items[id];
    }
    this.emit('change');
  },

  getState: function() {
    return {
      items: this.items,
      qty: this.getQty(),
      subtotal: this.getSubTotal()
    };
  }

});

module.exports = CartStore;
{'fraction_non_alphanumeric': 0.1774249223334484, 'fraction_numerical': 0.004142216085605799, 'mean_word_length': 2.483173076923077, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3076053', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1053, 'n_words': 189}