<commit_before>import R from 'ramda';
import applyReducers from '../utils/applyReducers';

import { links } from './links';
import { nodes } from './nodes';

import {
  PATCH_RENAME,
  PATCH_MOVE,
} from '../actionTypes';

export const patchReducer = (id) => {
  const patchId = id;
  const initialPatchState = {
    id: patchId,
    folderId: null,
    name: `Patch #${patchId}`,
  };

  return (state = initialPatchState, action) => {
    const reducers = {
      links,
      nodes,
    };

    if (
      action &&
      action.hasOwnProperty('meta') &&
      action.meta.hasOwnProperty('patchId') &&
      parseInt(action.meta.patchId, 10) !== parseInt(patchId, 10)
    ) {
      return state;
    }

    switch (action.type) {
      case PATCH_RENAME:
        return R.assoc('name', action.payload.name, state);
      case PATCH_MOVE:
        return R.assoc('folderId', action.payload.folderId, state);
      default:
        return applyReducers(reducers, R.merge(initialPatchState, state), action, patchId);
    }
  };
};<commit_msg>fix(undoable): fix bug with undoable<commit_after>import R from 'ramda';
import applyReducers from '../utils/applyReducers';

import { links } from './links';
import { nodes } from './nodes';

import {
  PATCH_RENAME,
  PATCH_MOVE,
} from '../actionTypes';

export const patchReducer = (id) => {
  const patchId = id;
  const initialPatchState = {
    id: patchId,
    folderId: null,
    name: `Patch #${patchId}`,
  };

  return (state = initialPatchState, action) => {
    const reducers = {
      links,
      nodes,
    };

    let istate = state;

    const hasInitialKeys = R.compose(
      R.allPass,
      R.map(R.has),
      R.keys
    )(initialPatchState);

    if (!hasInitialKeys(state)) {
      istate = R.merge(initialPatchState, state);
    }

    if (
      action &&
      action.hasOwnProperty('meta') &&
      action.meta.hasOwnProperty('patchId') &&
      parseInt(action.meta.patchId, 10) !== parseInt(patchId, 10)
    ) {
      return state;
    }

    switch (action.type) {
      case PATCH_RENAME:
        return R.assoc('name', action.payload.name, state);
      case PATCH_MOVE:
        return R.assoc('folderId', action.payload.folderId, state);
      default:
        return applyReducers(reducers, istate, action, patchId);
    }
  };
};
{'fraction_non_alphanumeric': 0.14161974880900824, 'fraction_numerical': 0.0034647033347769596, 'mean_word_length': 2.701923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5152667', 'n_tokens_mistral': 766, 'n_tokens_neox': 754, 'n_words': 170}