<commit_before>import destroyComponent from '../../app/profile/destroycomponent';
import errorDialog from '../../app/errorDialog';
import {itemRE} from '../../support/constants';
import updateUsedCount from './updateUsedCount';

function updateComponentCounts(itemId) {
  var delBtn = document.querySelector('#fshTally [data-compid="' + itemId +
    '"]');
  if (!delBtn) {return;}
  var countDom = delBtn.parentNode.parentNode.children[1];
  var count = Number(countDom.textContent) - 1;
  countDom.textContent = count.toString();
}

function compDeleted(self, itemId) {
  return function(data) {
    // console.log('data', data);
    if (data.s) {
      updateComponentCounts(itemId);
      updateUsedCount(1);
      if (self.parentNode) {self.parentNode.innerHTML = '';}
    }
  };
}

function delComponent(self) { // jQuery.min
  var tipped = self.parentNode.children[0].children[0].dataset.tipped;
  var matches = tipped.match(itemRE);
  var itemId = matches[1];
  var componentId = matches[2];
  // console.log('a=', componentId, 'b=', itemId);
  destroyComponent([componentId])
    .pipe(errorDialog)
    .done(compDeleted(self, itemId));
}

export default function componentDeleteHandler(evt) {
  if (evt.target.classList.contains('compDelBtn')) {
    delComponent(evt.target);
    return true;
  }
}<commit_msg>reduce nesting<commit_after>import destroyComponent from '../../app/profile/destroycomponent';
import errorDialog from '../../app/errorDialog';
import {itemRE} from '../../support/constants';
import partial from '../../common/partial';
import updateUsedCount from './updateUsedCount';

function updateComponentCounts(itemId) {
  var delBtn = document.querySelector('#fshTally [data-compid="' + itemId +
    '"]');
  if (!delBtn) {return;}
  var countDom = delBtn.parentNode.parentNode.children[1];
  var count = Number(countDom.textContent) - 1;
  countDom.textContent = count.toString();
}

function compDeleted(self, itemId, data) {
  if (data.s) {
    updateComponentCounts(itemId);
    updateUsedCount(1);
    if (self.parentNode) {self.parentNode.innerHTML = '';}
  }
}

function delComponent(self) { // jQuery.min
  var tipped = self.parentNode.children[0].children[0].dataset.tipped;
  var matches = tipped.match(itemRE);
  var itemId = matches[1];
  var componentId = matches[2];
  destroyComponent([componentId])
    .pipe(errorDialog)
    .done(partial(compDeleted, self, itemId));
}

export default function componentDeleteHandler(evt) {
  if (evt.target.classList.contains('compDelBtn')) {
    delComponent(evt.target);
    return true;
  }
}
{'fraction_non_alphanumeric': 0.15578865578865578, 'fraction_numerical': 0.005439005439005439, 'mean_word_length': 4.3312629399585925, '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': '528201', 'n_tokens_mistral': 784, 'n_tokens_neox': 806, 'n_words': 161}