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

Change all containers in base components to use context for selectors #740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shorja
Copy link

@shorja shorja commented Sep 18, 2017

Griddle major version

1.9.0

Changes proposed in this pull request

Convert all references to dataSelectors file in components to the context.selectors

Why these changes are made

This allows plugins to override selectors in the base components without having to wholesale copy them. Would this potentially be a dangerous change from a consumers of Griddle perspective?

Are there tests?

No

@dahlbyk
Copy link
Contributor

dahlbyk commented Sep 19, 2017

Love it! I think we can pretty confident this isn't a breaking change, simply because we're not changing the exported selectors that plugins have had to reference until now. This does make selectors an even more explicit part of the public API, though, so we'll need to be more careful about 1) deciding which to export, and 2) how they are designed (esp. with regard to exposing the immutable internals).

While we're at it, any thoughts on avoiding this pattern?

@joellanciaux
Copy link
Member

Very cool 👍

@dahlbyk regarding the extra dataSelectors exports from the localSelectors, we should be able to simply remove them for the next version. Would that be worthwhile to include with this update?

@dahlbyk
Copy link
Contributor

dahlbyk commented Sep 20, 2017

On further consideration, that particular pattern isn't the problem (though it will be nice to get rid of all the copy/paste). I'm glad to contribute that cleanup if @shorja doesn't wish to add it to this PR.

The pattern I meant to ask about manifests here: LocalPlugin needs to duplicate hasNextSelector, unchanged, just to use the modified maxPageSelector. There's actually less of that duplication in LocalPlugin than I expected, but I ask because I had run into a situation (pre-#718) where customizing sortedDataSelector would have required basically cloning the entire plugin, due to cascading dependencies. Not sure if there's any way to defer composition of selectors?

@joellanciaux
Copy link
Member

Yeah, cascading dependencies are a bit of an issue at the moment.

I believe @ryanlanciaux (who's currently in transit) can speak a little more about this, but I think he's been working on something that should handle some of the selector composition issues.

@shorja
Copy link
Author

shorja commented Sep 20, 2017

@dahlbyk @joellanciaux @ryanlanciaux I'm also working on a solution to the problem of duplicated selectors in plugins, I'll post it in another PR since its not specifically related and might be a bit more of a dangerous change, should have that up sometime today.

Copy link
Contributor

@dahlbyk dahlbyk left a comment

Choose a reason for hiding this comment

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

Added some feedback on the code; feel free to squash those changes.

Can you also check if any of the plugin components could use context for selectors?

// cellPropertiesSelector,
// classNamesForComponentSelector,
// stylesForComponentSelector
//} from '../selectors/dataSelectors';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the commented lines.

@@ -35,7 +38,7 @@ const ComposedRowContainer = OriginalComponent => compose(
}),
)(props => (
<OriginalComponent
{...props}
{...props}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this onto a single line, like the other components:

)(props => <OriginalComponent {...props} />);

It occurs to me that this is essentially a HOC identity function. @ryanlanciaux @joellanciaux is there a reason you haven't returned the result of compose() directly?

-const ComposedRowContainer = OriginalComponent => compose(
+const ComposedRowContainer = compose(
...
-)(props => <OriginalComponent {...props} />);
+);

import { textSelector, classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors';
import { toggleSettings as toggleSettingsAction } from '../actions';

const enhancedSettingsToggle = OriginalComponent => compose(
getContext({
selectors: PropTypes.object
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, and elsewhere, please ensure you have a trailing comma for consistency.

rowIds={visibleRowIds}
Row={Row}
style={style}
className={className}
Copy link
Contributor

Choose a reason for hiding this comment

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

This component can pass-thru props directly, like the other components:

)(props => <OriginalComponent {...props} />);

Copy link
Contributor

Choose a reason for hiding this comment

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

Clarification: please rename visibleRowIds to rowIds so props can pass-thru directly.

mapProps(props => {
const { components, ...otherProps } = props;
const { components, selectors, ...otherProps } = props;
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this is the only place you're pulling selectors out of otherProps. I think it's better this way, since selectors isn't meant to be exposed to the wrapped component - can you add repeat this change elsewhere?

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