How to use understory - 8 common examples

To help you get started, we’ve selected a few understory 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
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)),
  overBranch(flow(getDragCount, gte(0)), blurReducer),
)

// Can not overwrite value.
export const openReducer = (state, payload = {}) => ({
  ...state,
  focus: true,
  id: defaultTo(defaultTo(null, state.id), payload.id),
  initialValue: defaultTo(
    defaultTo(defaultTo(null, state.value), state.initialValue),
    payload.initialValue,
  ),
  isTouched: true,
  value: defaultTo(defaultTo(null, payload.initialValue), state.value),
})

export const setSaved = resetFields(['error', 'isSaving', 'savedProgress'])
github cape-io / redux-field / src / utils.js View on Github external
export const progress = (progressKey, totalKey) => flow(
  at([progressKey, totalKey]),
  overBranch(every(isNumber), progPercent, stubFalse),
)
// parseInt((progress / total) * 100, 10)
github cape-io / redux-field / src / utils.js View on Github external
export const progPercent = flow(spread(divide), multiply(100), round)
export const progress = (progressKey, totalKey) => flow(
  at([progressKey, totalKey]),
  overBranch(every(isNumber), progPercent, stubFalse),
)
// parseInt((progress / total) * 100, 10)
export const eventProg = progress('loaded', 'total')
export const fireProg = progress('bytesTransferred', 'totalBytes')
export function objProg(status) {
  let res = eventProg(status)
  if (res === false) res = fireProg(status)
  if (res === false) throw new Error('Unable to get progress from event object.')
  return res
}
export const getProgress = overBranch(isObject, objProg, parseInt(10))

export const mapPartial = curry((obj, arg) => mapValues(callWith(arg), obj))
github cape-io / redux-field / src / reducer.js View on Github external
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) {
    return setValue(applyError(state, payload.error), payload.value)
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
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)),
  overBranch(flow(getDragCount, gte(0)), blurReducer),
)

// Can not overwrite value.
export const openReducer = (state, payload = {}) => ({
  ...state,
  focus: true,
  id: defaultTo(defaultTo(null, state.id), payload.id),
  initialValue: defaultTo(
    defaultTo(defaultTo(null, state.value), state.initialValue),
    payload.initialValue,
  ),
  isTouched: true,
  value: defaultTo(defaultTo(null, payload.initialValue), state.value),
})
github cape-io / redux-field / src / actions.js View on Github external
  memoize(prefix => mapValues(callWith(prefix), actions)),
)
github cape-io / redux-field / src / utils.js View on Github external
export const mapPartial = curry((obj, arg) => mapValues(callWith(arg), obj))

understory

Composable utility functions based on lodash fp.

ISC
Latest version published 1 year ago

Package Health Score

46 / 100
Full package analysis