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

pass ownProps to areStatesEqual #865

Closed
wants to merge 1 commit into from
Closed

Conversation

z-vr
Copy link

@z-vr z-vr commented Feb 1, 2018

We have a use case when we need to use areStatesEqual and access ownProps at the same time. This PR solves the problem.

function compareStates(paths = [], a, b) {
    return paths.filter((path) => {
        const valueA = get(a, path);
        const valueB = get(b, path);
        return valueA !== valueB;
    });
}

const mapStateToProps = ({
    data: {
        campaign,
    },
}, { data: { id } }) => {
    const campaigns = getEntities(campaign, 'client_id', id);
    return {
        campaigns,
    };
};

export default connect(mapStateToProps, null, null, {
    areStatesEqual(prevState, nextState, { id }) {
        const paths = ['data.campaign.by.client_id.${id}.ids'];
        const differentPaths = compareStates(paths, prevState, nextState);
        const areEqual = differentPaths.length === 0;
        if (!areEqual) {
            console.log('[!] %s are not equal', differentPaths.join());
        }
        return areEqual;
    },
})(Client);

@timdorr
Copy link
Member

timdorr commented Feb 1, 2018

This was already discussed in #781

@timdorr timdorr closed this Feb 1, 2018
@z-vr
Copy link
Author

z-vr commented Feb 1, 2018

@timdorr it doesn't make any sense to me why you would not allow to access own properties in this method. The use case is exactly the same as the author you linked, and you're forcing me to run mapStateToProp which I do want to avoid. If your users are asking for it why is it so difficult? What's the argument against it?

You said

I would work to make that easier to query by doing some of the work upfront in your reducer.

But it's already easy for me to query, I just don't even want to query when irrelevant slices change. Is this too big of an ask?

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.

2 participants