<commit_before>import { Map } from 'immutable'

/**
 * The start action for the update reducer
 * @param  {Immutable.Map} state - current reducer state
 * @param  {Object} action - action object
 *
 * @return {Immutable.Map} - updated state
 */
export const start = (state, action) => {

  const uid = action.record.get(action.uidField)

  // Create updated record tuple
  // We have to create a tuple here in order to preserve the Integer typed keys

  const previousRecord = state.getIn(['raw', uid])
  const updatedRecordTuple = Map([[uid, previousRecord.merge(action.record)]])

  // Create tuple for previous version of the item
  const previousRecordTuple = Map([[uid, previousRecord]])

  return state.withMutations(map => {
    // Optimistically update the record
    map.set('raw', state.get('raw').merge(updatedRecordTuple))

    // Save previous version in case the update fails
    map.set('pendingUpdate', state.get('pendingUpdate').merge(previousRecordTuple))<commit_msg>add record to raw while updating if not already in story<commit_after>import { Map } from 'immutable'

/**
 * The start action for the update reducer
 * @param  {Immutable.Map} state - current reducer state
 * @param  {Object} action - action object
 *
 * @return {Immutable.Map} - updated state
 */
export const start = (state, action) => {

  const uid = action.record.get(action.uidField)

  // Get previous record
  const previousRecord = state.getIn(['raw', uid])

  // Create updated record tuple
  // We have to create a tuple here in order to preserve the Integer typed keys
  // If there is no previous record we add a new record
  const updatedRecord = previousRecord ? previousRecord.merge(action.record) : action.record
  const updatedRecordTuple = Map([[uid, updatedRecord]])

  return state.withMutations(map => {
    // Optimistically update the record
    map.set('raw', state.get('raw').merge(updatedRecordTuple))

    if(previousRecord) {
      // Save previous version in case the update fails
      const previousRecordTuple = Map([[uid, previousRecord]])
      map.set('pendingUpdate', state.get('pendingUpdate').merge(previousRecordTuple))
    }
{'fraction_non_alphanumeric': 0.11245353159851301, 'fraction_numerical': 0.0, 'mean_word_length': 3.926773455377574, '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': '734143', 'n_tokens_mistral': 587, 'n_tokens_neox': 580, 'n_words': 203}