kettanaito / react-advanced-form

Functional reactive forms. Multi-layer validation, custom styling, field grouping, reactive props, and much more.
https://redd.gitbook.io/react-advanced-form
MIT License
217 stars 24 forks source link

Consolidate fields stitching into high-order function #358

Closed kettanaito closed 5 years ago

kettanaito commented 5 years ago

What:

There are multiple Form methods that flatten and stitch the fields to perform update operations. The flattening/stitching part is really repetitive, and can be isolated into a high-order function.

Why:

This will decrease the amount of code to comprehend to understand a method. It will also make class methods smaller, and more maintainable.

How:

const transformFields = (transformer) => {
  return R.compose(
    fieldUtils.stitchFields,
    transformer,
    fieldUtils.flattenFields,
  )
}

// usage
unregisterFields = (fieldsList) => {
  const nextFields = transformFields(
    R.reject(...)
  )
}
kettanaito commented 5 years ago

This is reasonable and may be implemented during 2.0. Closing for now to prevent scope distortion.