Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'])
export const progress = (progressKey, totalKey) => flow(
at([progressKey, totalKey]),
overBranch(every(isNumber), progPercent, stubFalse),
)
// parseInt((progress / total) * 100, 10)
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))
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)
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) {
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),
})
memoize(prefix => mapValues(callWith(prefix), actions)),
)
export const mapPartial = curry((obj, arg) => mapValues(callWith(arg), obj))