<commit_before>import {getFormValues, actions as formActions, isValid} from 'redux-form'
import {CHANGE, UPDATE_SYNC_ERRORS, INITIALIZE} from 'redux-form/es/actionTypes'
import {externalEvents, form as formUtil} from 'tocco-app-extensions'
import {all, call, put, select, takeEvery, takeLatest} from 'redux-saga/effects'

import * as actions from './actions'

const FORM_ID = 'simpleForm'
export const inputSelector = state => state.input
export const selector = state => state.simpleForm

export default function* sagas() {
  yield all([
    takeEvery(actions.INITIALIZE_QUESTION_FORM, initialize),
    takeEvery(actions.SUBMIT, submit),
    takeEvery(actions.CANCEL, cancel),
    takeLatest(CHANGE, change),
    takeLatest(UPDATE_SYNC_ERRORS, change),
    takeLatest(INITIALIZE, change)
  ])
}

export function* initialize() {
  const {form} = yield select(inputSelector)
  const fieldDefinitions = yield call(formUtil.getFieldDefinitions, form)
  const defaultValues = yield call(formUtil.getDefaultValues, fieldDefinitions)
  yield put(formActions.initialize(FORM_ID, defaultValues))
}

export function* submit() {
  const values = yield select(getFormValues(FORM_ID))
  yield put(externalEvents.fireExternalEvent('onSubmit', {values}))
}

export function* cancel() {
  const values = yield select(getFormValues(FORM_ID))
  yield put(externalEvents.fireExternalEvent('onCancel', {values}))
}

export function* change() {
  const values = yield select(getFormValues(FORM_ID))
  const valid = yield select(isValid(FORM_ID))
  yield put(externalEvents.fireExternalEvent('onChange', {values, valid}))
}
<commit_msg>feat(simple-form): use real paths when firing external events<commit_after>import {getFormValues, actions as formActions, isValid} from 'redux-form'
import {CHANGE, UPDATE_SYNC_ERRORS, INITIALIZE} from 'redux-form/es/actionTypes'
import {externalEvents, form as formUtil} from 'tocco-app-extensions'
import {all, call, put, select, takeEvery, takeLatest} from 'redux-saga/effects'

import * as actions from './actions'

const FORM_ID = 'simpleForm'
export const inputSelector = state => state.input
export const selector = state => state.simpleForm

export default function* sagas() {
  yield all([
    takeEvery(actions.INITIALIZE_QUESTION_FORM, initialize),
    takeEvery(actions.SUBMIT, submit),
    takeEvery(actions.CANCEL, cancel),
    takeLatest(CHANGE, change),
    takeLatest(UPDATE_SYNC_ERRORS, change),
    takeLatest(INITIALIZE, change)
  ])
}

export function* initialize() {
  const {form} = yield select(inputSelector)
  const fieldDefinitions = yield call(formUtil.getFieldDefinitions, form)
  const defaultValues = yield call(formUtil.getDefaultValues, fieldDefinitions)
  yield put(formActions.initialize(FORM_ID, defaultValues))
}

export function* submit() {
  const values = yield getValues()
  yield put(externalEvents.fireExternalEvent('onSubmit', {values}))
}

export function* cancel() {
  const values = yield getValues()
  yield put(externalEvents.fireExternalEvent('onCancel', {values}))
}

export function* change() {
  const values = yield getValues()
  const valid = yield select(isValid(FORM_ID))
  yield put(externalEvents.fireExternalEvent('onChange', {values, valid}))
}

function* getValues() {
  return Object.entries(yield select(getFormValues(FORM_ID)))
    .reduce((acc, [key, value]) => {
      return {
        ...acc,
        [key.replace('--', '.')]: value
      }
    }, {})
}

{'fraction_non_alphanumeric': 0.11812627291242363, 'fraction_numerical': 0.0, 'mean_word_length': 5.561068702290076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '6535853', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1028, 'n_words': 261}