Skip to content

Fix caching in "for narrow" selectors #3015

@gnprice

Description

@gnprice

When we want to pass an argument to a selector, like props.narrow to getRenderedMessages, we currently do so in a way that totally defeats Reselect's caching. We should fix this.

See discussion in chat. In particular, on what to do instead:

The solution recommended in the Reselect docs is to push the inspection of props inside the selector:
https://github.com/reduxjs/reselect#accessing-react-props-in-selectors

I don't love that solution -- it feels awfully implicit to me. [...] I'd much rather stick to passing specifically the narrow down to the selectors, like we currently do.

I guess there's nothing in the Reselect code (AFAICT) that depends on that "props" argument actually being the props of any React component. So we could just say getRenderedMessages(state, props.narrow), and have all the ...ForNarrow selectors take a second argument of type Narrow, and that may just all work great.

(We'd be treating that Narrow as what the Reselect docs expect to be "props".)

So instead of defining selectors so that their call sites look like getRenderedMessages(props.narrow)(state), we should define them so they're called like getRenderedMessages(state, props.narrow).

I don't think this is currently a top priority, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions