src/create-glamorous.js
function getPropsToApply(propsToApply, accumulator, props, context) {
  // using forEach rather than reduce here because the reduce solution
  // effectively did the same thing because we manipulate the `accumulator`
  propsToApply.forEach(propsToApplyItem => {
    if (typeof propsToApplyItem === 'function') {
      return Object.assign(
        accumulator,
        propsToApplyItem(Object.assign({}, accumulator, props), context),
      )
    } else if (Array.isArray(propsToApplyItem)) {
      return Object.assign(
        accumulator,
        getPropsToApply(propsToApplyItem, accumulator, props, context),
      )
    }
    return Object.assign(accumulator, propsToApplyItem)
  })
  // props wins
  return Object.assign(accumulator, props)
}
function getPropsToApply(propsToApply, accumulator, props, context) {
  // using forEach rather than reduce here because the reduce solution
  // effectively did the same thing because we manipulate the `accumulator`
  propsToApply.forEach(propsToApplyItem => {
    if (typeof propsToApplyItem === 'function') {
      return Object.assign(
        accumulator,
        propsToApplyItem(Object.assign({}, accumulator, props), context),
      )
    } else if (Array.isArray(propsToApplyItem)) {
      return Object.assign(
        accumulator,
        getPropsToApply(propsToApplyItem, accumulator, props, context),
      )
    }
    return Object.assign(accumulator, propsToApplyItem)
  })
  // props wins
  return Object.assign(accumulator, props)
}
function getPropsToApply ( propsToApply , accumulator , props , context ) { // using forEach rather than reduce here because the reduce solution // effectively did the same thing because we manipulate the `accumulator` propsToApply . forEach ( propsToApplyItem => { if ( typeof propsToApplyItem === 'function' ) { return Object . assign ( accumulator , propsToApplyItem ( Object . assign ( { } , accumulator , props ) , context ) , ) } else if ( Array . isArray ( propsToApplyItem ) ) { return Object . assign ( accumulator , getPropsToApply ( propsToApplyItem , accumulator , props , context ) , ) } return Object . assign ( accumulator , propsToApplyItem ) } ) // props wins return Object . assign ( accumulator , props ) }
reduces the propsToApply given to a single props object
@param {Array} propsToApply an array of propsToApply objects:
- object
- array of propsToApply items
- function that accepts the accumulated props and the context
@param {Object} accumulator an object to apply props onto
@param {Object} props the props that should ultimately take precedence
@param {*} context the context object
@return {Object} the reduced props
reduces the propsToApply given to a single props object