Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mergeProps to optionally accept a factory style function #523

Closed
wants to merge 101 commits into from

Conversation

neeharv
Copy link

@neeharv neeharv commented Oct 17, 2016

I have a very similar use case to #488

I've reused @bsideup's code as-is, with the same test. We've started moving to v5 in production, hoping to see this soon in there!

Obviously that didn't happen...

if (typeof nextMergedProps === 'function') {
nextMergedProps = nextMergedProps(stateProps, dispatchProps, ownProps)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is complete; it looks like it's still going to call the original factory method every time through the loop. I'd expect to see mergeProps copied into a variable that is overwritten with its result when the result is a function, similar to wrapMapToPropsFunc

@connect(
state => state,
() => ({ sum }),
() => (stateProps, dispatchProps, parentProps) => ({
Copy link
Contributor

@jimbolla jimbolla Oct 17, 2016

Choose a reason for hiding this comment

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

The test should probably cover that the factory part of the mergeProps method is only called once, related to my previous comment. I'd do something like

() => {
  mergePropFactoryCalls += 1;
  return (stateProps, dispatchProps, parentProps) => ({
    sum: () => dispatchProps.sum(stateProps.a, parentProps.b)
  });
}

and then assert that it equals 1 after dispatching several actions. Or use the spy stuff.

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense. Should this be in a separate test or I'll augment the existing one?

@timdorr timdorr added this to the 5.1 milestone Nov 8, 2016
@timdorr timdorr closed this Dec 14, 2016
@timdorr timdorr changed the base branch from next to master December 14, 2016 17:22
@timdorr timdorr reopened this Dec 14, 2016
@timdorr
Copy link
Member

timdorr commented Feb 17, 2017

Any update on this, @neeharv?

…ops pass. BREAKING CHANGE: requires setting an option parameter mapStateIsFactory/mapDispatchIsFactory to signal factory methods.
…hind-the-scenes behavior of new implementation.
vhmth and others added 18 commits February 18, 2017 12:51
* Remove Style section

Obviously that didn't happen...

* Add es2015 modules export from redux project
* updates docs for changes in v5 (WORK IN PROGRESS)

* update docs for changes in v5

* removes unused code from example

* adds a tags to api.md for direct linking
…duxjs#477)

* groups factories options and move *areEqual defaults into connect

* refactors connect so that new "factories" extension points aren't in main API
The `current` variable would be set to `null` when `clear()` was called, which would cause an exception if there was more than one listener. The new test would fail before this change.
@neeharv
Copy link
Author

neeharv commented Feb 18, 2017

@timdorr this slipped my mind completely! I'll work on the changes requested over this weekend

@neeharv
Copy link
Author

neeharv commented Feb 18, 2017

@timdorr @jimbolla I've cleaned up the test and memoized the response of the factory. Also updated API docs. Do let me know if there is anything else you'd like me to do. Thanks!

@timdorr
Copy link
Member

timdorr commented Feb 18, 2017

Can you revise the branch on the latest master? There are a lot of junk commits in here.

@neeharv
Copy link
Author

neeharv commented Feb 18, 2017

@timdorr much easier to just do it in a new branch for me. The new PR is here is #626. Closing this so you can take a look there! Thanks.

@neeharv neeharv closed this Feb 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants