<commit_before>import _ from 'lodash';

export const create = (state, action, path, idKey = 'id') => {
  if(action.error === true) {
    return state;
  }

  return state.merge(Immutable.fromJS(_.get(action, path)));
};

export const read = (state, action, path, idKey = 'id') => {
  if(action.error === true) {
    return state;
  }

  return state.merge(Immutable.fromJS(_.get(action, path)));
};

export const update = (state, action, path, idKey = 'id') => {
  if(action.error === true) {
    return state;
  }

  return state.merge(Immutable.fromJS(_.get(action, path)));
};

export const del = (state, action, path, idKey = 'id') => {
  if(action.error === true) {
    return state;
  }

  return state.filterNot(entity => {
    const id = entity.get(idKey);
    return _.includes(_.get(action, path), id);
  });
};


const reducer = (reducer, config) => {
  if(!_.isArray(config.create)) {
    config.create = [config.create];
  }

  if(!_.isArray(config.read)) {
    config.read = [config.read];
  }

  if(!_.isArray(config.update)) {
    config.update = [config.update];
  }

  if(!_.isArray(config.delete)) {
    config.delete = [config.delete];
  }

  return (state, action) => {

    if(state == null) {
      return reducer(state, action);
    }

    if(_.includes(config.create, action.type)) {
      return create(state, action, config.path, config.idKey);
    }

    if(_.includes(config.read, action.type)) {
      return read(state, action, config.path, config.idKey);
    }

    if(_.includes(config.update, action.type)) {
      return update(state, action, config.path, config.idKey);
    }

    if(_.includes(config.delete, action.type)) {
      return del(state, action, config.path, config.idKey);
    }

    return reducer(state, action);
  };
};

export default reducer;<commit_msg>Moving out of using immutable.<commit_after>import _ from 'lodash';

export const create = (state, action, idKey = 'id') => {
  if(action.error === true) {
    return state;
  }

  if(_.isArray(action.payload) === true) {
    return _.assign({}, state, _.keyBy(action.payload, idKey));
  }

  return _.assign({}, state, { [action.payload.id]: action.payload });
};

export const read = (state, action, idKey = 'id') => {
  if(action.error === true) {
    return state;
  }

  if(_.isArray(action.payload) === true) {
    return _.assign({}, state, _.keyBy(action.payload, idKey));
  }

  return _.assign({}, state, { [action.payload.id]: action.payload });
};

export const update = (state, action, idKey = 'id') => {
  if(action.error === true) {
    return state;
  }

  if(_.isArray(action.payload) === true) {
    return _.merge({}, state, _.keyBy(action.payload, idKey));
  }

  return _.merge({}, state, { [action.payload.id]: action.payload });
};

export const del = (state, action, idKey = 'id') => {
  if(action.error === true) {
    return state;
  }

  if(_.isArray(action.payload) === true) {
    return _.omit(_.clone(state), _.map(action.payload, idKey));
  }

  return _.omit(_.clone(state), action.payload.id);
};

const reducer = (reducer, config) => {
  if(!_.isArray(config.create)) {
    config.create = [config.create];
  }

  if(!_.isArray(config.read)) {
    config.read = [config.read];
  }

  if(!_.isArray(config.update)) {
    config.update = [config.update];
  }

  if(!_.isArray(config.delete)) {
    config.delete = [config.delete];
  }

  return (state, action) => {

    if(state == null) {
      return reducer(state, action);
    }

    if(_.includes(config.create, action.type)) {
      return create(state, action, config.path, config.idKey);
    }

    if(_.includes(config.read, action.type)) {
      return read(state, action, config.path, config.idKey);
    }

    if(_.includes(config.update, action.type)) {
      return update(state, action, config.path, config.idKey);
    }

    if(_.includes(config.delete, action.type)) {
      return del(state, action, config.path, config.idKey);
    }

    return reducer(state, action);
  };
};

export default reducer;
{'fraction_non_alphanumeric': 0.18195413758723827, 'fraction_numerical': 0.0, 'mean_word_length': 3.2420718816067655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '6111655', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1348, 'n_words': 280}