Repository URL to install this package:
|
Version:
1.3.3 ▾
|
import { curry } from 'chain-able-boost'
import { AnyObj, AnyProps, Without } from './typings'
/**
* @alias unknownProps
* @alias remainingProps
* @name passThroughProps
*
* @return props that were not in the proptypes to pass through
*/
function _passThroughProps<Types = AnyObj, Props = AnyProps>(
types: Types,
props: AnyProps
): Without<Types, Props> {
// list
// @todo why types.types?
const supportedPropsList = Object.keys((types as any).types)
const currentPropsList = Object.keys(props)
// filter
const isUnsupported = propName => !supportedPropsList.includes(propName)
const remaining = currentPropsList.filter(isUnsupported)
// define
const propsNotInSupportedList = {}
remaining.forEach(propName => {
propsNotInSupportedList[propName] = props[propName]
})
// filter / alias
// propsNotInSupportedList = autofixProps(propsNotInSupportedList, this.props)
return propsNotInSupportedList as any
}
const passThroughProps = curry(2, _passThroughProps)
export { passThroughProps }
export { passThroughProps as toRemainingProps }
export { passThroughProps as toUnknownProps }
export default passThroughProps