<commit_before>'use strict';

const defaultState = [];

function flatten(acc, cur) {
  cur.map(c => {
    acc.push(c);
  });

  return acc;
}

export default (state=defaultState, action) => {
  switch (action.type) {
  case 'DOCS_FETCH':
    return action.docs.map(d => d.lang || []).reduce(flatten, []).uniqueCount();
  case 'DOC_INSERT':
    let tags = [...state];
    action.doc.lang.map(tag => {
      tags.map(el => {
        if (el.tag === tag) {
          el.count++;
        }
      });
    });
    return tags;
  // TODO DOC_DELETE
  default:
    return state;
  }
};<commit_msg>only check for new tags when there is a lang object<commit_after>'use strict';

const defaultState = [];

function flatten(acc, cur) {
  cur.map(c => {
    acc.push(c);
  });

  return acc;
}

export default (state=defaultState, action) => {
  switch (action.type) {
  case 'DOCS_FETCH':
    return action.docs.map(d => d.lang || []).reduce(flatten, []).uniqueCount();
  case 'DOC_INSERT':
    let tags = [...state];
    if (action.doc.lang) {
      action.doc.lang.map(tag => {
        tags.map(el => {
          if (el.tag === tag) {
            el.count++;
          }
        });
      });
    }
    return tags;
  // TODO DOC_DELETE
  default:
    return state;
  }
};
{'fraction_non_alphanumeric': 0.18080888183980967, 'fraction_numerical': 0.0, 'mean_word_length': 2.277922077922078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3190481', 'n_tokens_mistral': 445, 'n_tokens_neox': 438, 'n_words': 96}