<commit_before>/** @jsx React.DOM */

var jQuery = require("jquery");
var Reflux = require("reflux");

var AlertActions = require("../actions/alertActions");
var GroupActions = require('../actions/groupActions');
var MemberListStore = require("../stores/memberListStore");
var utils = require("../utils");

var ERR_CHANGE_ASSIGNEE = 'Unable to change assignee. Please try again.';
var ERR_SCHEDULE_DELETE = 'Unable to delete events. Please try again.';
var ERR_SCHEDULE_MERGE = 'Unable to merge events. Please try again.';
var ERR_UPDATE = 'Unable to update events. Please try again.';
var OK_SCHEDULE_DELETE = 'The selected events have been scheduled for deletion.';
var OK_SCHEDULE_MERGE = 'The selected events have been scheduled for merge.';

var GroupStore = Reflux.createStore({
  init() {
    this.items = [];
    this.statuses = {};
    this.pendingChanges = new utils.PendingChangeQueue();

    this.listenTo(GroupActions.assignTo, this.onAssignTo);
    this.listenTo(GroupActions.assignToError, this.onAssignToError);
    this.listenTo(GroupActions.assignToSuccess, this.onAssignToSuccess);
    this.listenTo(GroupActions.delete, this.onDelete);
    this.listenTo(GroupActions.deleteError, this.onDeleteError);
    this.listenTo(GroupActions.merge, this.onMerge);
    this.listenTo(GroupActions.mergeError, this.onMergeError);
    this.listenTo(GroupActions.update, this.onUpdate);
    this.listenTo(GroupActions.updateError, this.onUpdateError);
    this.listenTo(GroupActions.updateSuccess, this.onUpdateSuccess);
  },

  // TODO(dcramer): this should actually come from an action of some sorts
  loadInitialData(items) {
    this.items = [];
    this.statuses = {};
    this.pendingChanges.clear();

    var itemIds = new Set();
    items.forEach(item => {
      itemIds.add(item.id);
      this.items.push(item);
    });
    this.trigger(itemIds);
  },

  add(items) {
    if (!items instanceof Array) {
      items = [items];
    }

    var itemsById = {};
    items.forEach((item) => {
      itemsById[item.id] = item;
    });

    items.forEach((item, idx) => {
      if (itemsById[item.id]) {
        this.items[idx] = jQuery.extend(true, {}, item, itemsById[item.id]);
        delete itemsById[item.id];
      }
    });

    var itemIds = new Set();
    for (var itemId in itemsById) {
      this.items.push(itemsById[itemId]);
      itemIds.add(itemId);
    }

    this.trigger(itemIds);
  },<commit_msg>Fix initial itemIds<commit_after>/** @jsx React.DOM */

var jQuery = require("jquery");
var Reflux = require("reflux");

var AlertActions = require("../actions/alertActions");
var GroupActions = require('../actions/groupActions');
var MemberListStore = require("../stores/memberListStore");
var utils = require("../utils");

var ERR_CHANGE_ASSIGNEE = 'Unable to change assignee. Please try again.';
var ERR_SCHEDULE_DELETE = 'Unable to delete events. Please try again.';
var ERR_SCHEDULE_MERGE = 'Unable to merge events. Please try again.';
var ERR_UPDATE = 'Unable to update events. Please try again.';
var OK_SCHEDULE_DELETE = 'The selected events have been scheduled for deletion.';
var OK_SCHEDULE_MERGE = 'The selected events have been scheduled for merge.';

var GroupStore = Reflux.createStore({
  init() {
    this.items = [];
    this.statuses = {};
    this.pendingChanges = new utils.PendingChangeQueue();

    this.listenTo(GroupActions.assignTo, this.onAssignTo);
    this.listenTo(GroupActions.assignToError, this.onAssignToError);
    this.listenTo(GroupActions.assignToSuccess, this.onAssignToSuccess);
    this.listenTo(GroupActions.delete, this.onDelete);
    this.listenTo(GroupActions.deleteError, this.onDeleteError);
    this.listenTo(GroupActions.merge, this.onMerge);
    this.listenTo(GroupActions.mergeError, this.onMergeError);
    this.listenTo(GroupActions.update, this.onUpdate);
    this.listenTo(GroupActions.updateError, this.onUpdateError);
    this.listenTo(GroupActions.updateSuccess, this.onUpdateSuccess);
  },

  // TODO(dcramer): this should actually come from an action of some sorts
  loadInitialData(items) {
    this.items = [];
    this.statuses = {};
    this.pendingChanges.clear();

    var itemIds = new Set();
    items.forEach((item) => {
      itemIds.add(item.id);
      this.items.push(item);
    });
    this.trigger(itemIds);
  },

  add(items) {
    if (!items instanceof Array) {
      items = [items];
    }

    var itemsById = {};
    var itemIds = new Set();
    items.forEach((item) => {
      itemsById[item.id] = item;
      itemIds.add(item.id);
    });

    items.forEach((item, idx) => {
      if (itemsById[item.id]) {
        this.items[idx] = jQuery.extend(true, {}, item, itemsById[item.id]);
        delete itemsById[item.id];
      }
    });

    for (var itemId in itemsById) {
      this.items.push(itemsById[itemId]);
    }

    this.trigger(itemIds);
  },
{'fraction_non_alphanumeric': 0.13856289890879145, 'fraction_numerical': 0.0, 'mean_word_length': 3.689189189189189, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1686084', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1497, 'n_words': 328}