Skip to content

Conversation

@simenbrekken
Copy link
Contributor

Closes #19

@einarlove
Copy link
Member

Shouldn't actionProps be the last argument seen it will be the least used?

@simenbrekken
Copy link
Contributor Author

Won't all of them almost always be used? Otherwise your function would be discarding arguments.

@einarlove
Copy link
Member

einarlove commented Jan 23, 2017

const customMerge = (ownProps, ...rest) => ({
  ...rest,
  prop: ownProps.prop || rest.prop,
})

@simenbrekken
Copy link
Contributor Author

I reordered the arguments in the latest commit, let me know what you think.

@einarlove
Copy link
Member

einarlove commented Jan 24, 2017 via email

@simenbrekken
Copy link
Contributor Author

We could merge them before passing them into mergeProps as they will never collide, but an efficient cascading implementation would still be:

const assignCustomizer = (objectValue, sourceValue) => (
  _.isNil(objectValue) ? sourceValue : objectValue
)

const customMergeProps = (actionProps, subscriptionProps, ownProps) => {
  const cascadedProps = _.assignWith({}, ownProps, subscriptionProps, assignCustomizer)

  return {
    ...actionProps,
    ...cascadedProps
  }
}

src/connect.js Outdated
const actionProps = pickBy(firebaseProps, isFunction)
const subscriptionProps = this.state.subscriptionsState
const props = mergeProps(actionProps, subscriptionProps, this.props)
const props = mergeProps(this.props, subscriptionProps, actionProps)
Copy link
Member

@einarlove einarlove Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we do

const props = mergeProps(this.props, { ...actionProps, ...subscriptionProps })

instead? Why should the developer get three arguments to mergeProps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd want to add defaults to subscriptionProps as in the example above you would have to filter out actionProps by checking if they are functions or values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give an example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simenbrekken
Copy link
Contributor Author

Once again, Circle refuses to run tests so I'm merging this manually.

@simenbrekken simenbrekken merged commit f465022 into master Feb 23, 2017
@einarlove einarlove deleted the issue-19-merge-props branch February 24, 2017 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants