<commit_before>import fetch from 'isomorphic-fetch'

export const REQUEST_FORM = 'REQUEST_FORM'
export const RECEIVE_FORM = 'RECEIVE_FORM'

function requestForm(name) {
  return {
    type: REQUEST_FORM,
    name
  }
}

function receiveForm(name, json) {
  return {
    type: RECEIVE_FORM,
    name,
    form: json.form,
    receivedAt: Date.now()
  }
}

export function fetchForm(name) {
  return dispatch => {
    dispatch(requestForm(name))
    return fetch(`http://localhost:8080/nice2/rest/forms/${name}`)<commit_msg>Only fetch form if not already present<commit_after>import fetch from 'isomorphic-fetch'

export const REQUEST_FORM = 'REQUEST_FORM'
export const RECEIVE_FORM = 'RECEIVE_FORM'

function requestForm(name) {
  return {
    type: REQUEST_FORM,
    name
  }
}

function receiveForm(name, json) {
  return {
    type: RECEIVE_FORM,
    name,
    form: json.form,
    receivedAt: Date.now()
  }
}

export function fetchForm(name) {
  return (dispatch, getState) => {
    if (getState().forms[name]) {
      return null
    }
    dispatch(requestForm(name))
    return fetch(`http://localhost:8080/nice2/rest/forms/${name}`)
{'fraction_non_alphanumeric': 0.11940298507462686, 'fraction_numerical': 0.00877963125548727, 'mean_word_length': 3.810126582278481, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2841477', 'n_tokens_mistral': 389, 'n_tokens_neox': 380, 'n_words': 84}