How to use prairie - 5 common examples

To help you get started, we’ve selected a few prairie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cape-io / redux-field / src / reducer.js View on Github external
isSaving: false, // Bool.
  isTouched: false,
  valid: {}, // index of valid values.
  value: null, // Anything.
}

export const resetFields = fields => mergeWith(pick(fields, defaultState))

export const getDragCount = get('dragCount')

export const setFocus = mergeWith({ blur: false, focus: true, isTouched: true })
export const setClose = resetFields(['blur', 'focus'])

export const saving = set('isSaving', true)
export const isNewValue = (state, payload) => (!isUndefined(payload) && payload !== state.value)
export const setValue = overBranch(isNewValue, setIn('value'))
export const touched = overBranch(negate(get('isTouched')), set('isTouched', true))
export const changeReducer = flow(setValue, touched)

export const blurReducer = flow(
  changeReducer,
  resetFields(['dragCount', 'focus']),
  set('blur', true),
)

export const closeReducer = flow(setClose, touched)

export const applyError = flow(setIn('error'), touched)

export const clearError = set('error', defaultState.error)
export const errorReducer = (state, payload) => {
  if (payload.error && payload.value) {
github cape-io / redux-field / src / reducer.js View on Github external
payload.initialValue,
  ),
  isTouched: true,
  value: defaultTo(defaultTo(null, payload.initialValue), state.value),
})

export const setSaved = resetFields(['error', 'isSaving', 'savedProgress'])

export const savedReducer = (state, payload) => ({
  ...setSaved(state),
  id: getOr(state.id, 'id', payload),
  initialValue: state.value,
  savedValue: getOr(state.value, 'value', payload),
  value: getOr(state.value, 'value', payload),
})
export const saveProgressReducer = flow(setIn('savedProgress'), saving)

export const submitReducer = flow(
  setValue,
  setClose,
  saving,
)
export const metaReducer = ({ meta, ...state }, payload) => ({
  ...state,
  isTouched: true,
  meta: merge(meta, payload),
})

export const reducers = {
  [CLEAR]: () => defaultState,
  [CLEAR_ERROR]: clearError,
  // Should close also change initialValue?
github cape-io / redux-field / src / reducer.js View on Github external
initialValue: null, // Anything.
  invalid: {}, // index of invalid values.
  meta: null, // Anything.
  savedProgress: 0, // Percentage Number 0-99.
  savedValue: null,
  isSaving: false, // Bool.
  isTouched: false,
  valid: {}, // index of valid values.
  value: null, // Anything.
}

export const resetFields = fields => mergeWith(pick(fields, defaultState))

export const getDragCount = get('dragCount')

export const setFocus = mergeWith({ blur: false, focus: true, isTouched: true })
export const setClose = resetFields(['blur', 'focus'])

export const saving = set('isSaving', true)
export const isNewValue = (state, payload) => (!isUndefined(payload) && payload !== state.value)
export const setValue = overBranch(isNewValue, setIn('value'))
export const touched = overBranch(negate(get('isTouched')), set('isTouched', true))
export const changeReducer = flow(setValue, touched)

export const blurReducer = flow(
  changeReducer,
  resetFields(['dragCount', 'focus']),
  set('blur', true),
)

export const closeReducer = flow(setClose, touched)
github cape-io / redux-field / src / reducer.js View on Github external
export const saving = set('isSaving', true)
export const isNewValue = (state, payload) => (!isUndefined(payload) && payload !== state.value)
export const setValue = overBranch(isNewValue, setIn('value'))
export const touched = overBranch(negate(get('isTouched')), set('isTouched', true))
export const changeReducer = flow(setValue, touched)

export const blurReducer = flow(
  changeReducer,
  resetFields(['dragCount', 'focus']),
  set('blur', true),
)

export const closeReducer = flow(setClose, touched)

export const applyError = flow(setIn('error'), touched)

export const clearError = set('error', defaultState.error)
export const errorReducer = (state, payload) => {
  if (payload.error && payload.value) {
    return setValue(applyError(state, payload.error), payload.value)
  }
  return applyError(state, payload)
}

export const dragEnterReducer = flow(
  setFocus,
  update('dragCount', add(1)),
)

export const dragLeaveReducer = flow(
  update('dragCount', subtrahend(1)),
github cape-io / redux-field / src / reducer.js View on Github external
export const resetFields = fields => mergeWith(pick(fields, defaultState))

prairie

Add/Modify fields on an object with composable functions.

ISC
Latest version published 1 year ago

Package Health Score

46 / 100
Full package analysis

Popular prairie functions