Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules-modules / observable-utils / passThroughProps.ts
Size: Mime:
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