-
Notifications
You must be signed in to change notification settings - Fork 377
Change all containers in base components to use context for selectors #740
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,23 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import compose from 'recompose/compose'; | ||
| import getContext from 'recompose/getContext'; | ||
| import { connect } from '../utils/griddleConnect'; | ||
|
|
||
| import { classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
| //import { classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
| import { setFilter } from '../actions'; | ||
|
|
||
| const EnhancedFilter = OriginalComponent => connect((state, props) => ({ | ||
| className: classNamesForComponentSelector(state, 'Filter'), | ||
| style: stylesForComponentSelector(state, 'Filter'), | ||
| }), { setFilter })(props => <OriginalComponent {...props} />); | ||
| const EnhancedFilter = OriginalComponent => compose( | ||
| getContext({ | ||
| selectors: PropTypes.object | ||
| }), | ||
| connect( | ||
| (state, props) => ({ | ||
| className: props.selectors.classNamesForComponentSelector(state, 'Filter'), | ||
| style: props.selectors.stylesForComponentSelector(state, 'Filter'), | ||
| }), | ||
| { setFilter } | ||
| ) | ||
| )(props => <OriginalComponent {...props} />); | ||
|
|
||
| export default EnhancedFilter; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,21 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import compose from 'recompose/compose'; | ||
| import getContext from 'recompose/getContext'; | ||
| import { connect } from '../utils/griddleConnect'; | ||
|
|
||
| import { textSelector, hasNextSelector, classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
| //import { textSelector, hasNextSelector, classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
|
|
||
| const enhance = OriginalComponent => connect((state, props) => ({ | ||
| text: textSelector(state, { key: 'next' }), | ||
| hasNext: hasNextSelector(state, props), | ||
| className: classNamesForComponentSelector(state, 'NextButton'), | ||
| style: stylesForComponentSelector(state, 'NextButton'), | ||
| }))((props) => <OriginalComponent {...props} />); | ||
| const enhance = OriginalComponent => compose( | ||
| getContext({ | ||
| selectors: PropTypes.object | ||
| }), | ||
| connect((state, props) => ({ | ||
| text: props.selectors.textSelector(state, { key: 'next' }), | ||
| hasNext: props.selectors.hasNextSelector(state, props), | ||
| className: props.selectors.classNamesForComponentSelector(state, 'NextButton'), | ||
| style: props.selectors.stylesForComponentSelector(state, 'NextButton'), | ||
| })) | ||
| )((props) => <OriginalComponent {...props} />); | ||
|
|
||
| export default enhance; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,22 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import compose from 'recompose/compose'; | ||
| import getContext from 'recompose/getContext'; | ||
| import { connect } from '../utils/griddleConnect'; | ||
| import { textSelector, hasPreviousSelector, classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
| //import { textSelector, hasPreviousSelector, classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
|
|
||
| const enhance = OriginalComponent => connect((state, props) => ({ | ||
| text: textSelector(state, { key: 'previous' }), | ||
| hasPrevious: hasPreviousSelector(state, props), | ||
| className: classNamesForComponentSelector(state, 'PreviousButton'), | ||
| style: stylesForComponentSelector(state, 'PreviousButton'), | ||
| }))((props) => <OriginalComponent {...props} />); | ||
| const enhance = OriginalComponent => compose( | ||
| getContext({ | ||
| selectors: PropTypes.object | ||
| }), | ||
| connect( | ||
| (state, props) => ({ | ||
| text: props.selectors.textSelector(state, { key: 'previous' }), | ||
| hasPrevious: props.selectors.hasPreviousSelector(state, props), | ||
| className: props.selectors.classNamesForComponentSelector(state, 'PreviousButton'), | ||
| style: props.selectors.stylesForComponentSelector(state, 'PreviousButton'), | ||
| }) | ||
| ) | ||
| )((props) => <OriginalComponent {...props} />); | ||
|
|
||
| export default enhance; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,26 +5,29 @@ import compose from 'recompose/compose'; | |
| import mapProps from 'recompose/mapProps'; | ||
| import getContext from 'recompose/getContext'; | ||
|
|
||
| import { | ||
| columnIdsSelector, | ||
| rowDataSelector, | ||
| rowPropertiesSelector, | ||
| classNamesForComponentSelector, | ||
| stylesForComponentSelector, | ||
| } from '../selectors/dataSelectors'; | ||
| //import { | ||
| // columnIdsSelector, | ||
| // rowDataSelector, | ||
| // rowPropertiesSelector, | ||
| // classNamesForComponentSelector, | ||
| // stylesForComponentSelector, | ||
| //} from '../selectors/dataSelectors'; | ||
| import { valueOrResult } from '../utils/valueUtils'; | ||
|
|
||
| const ComposedRowContainer = OriginalComponent => compose( | ||
| getContext({ | ||
| components: PropTypes.object, | ||
| selectors: PropTypes.object | ||
| }), | ||
| connect((state, props) => ({ | ||
| columnIds: columnIdsSelector(state), | ||
| rowProperties: rowPropertiesSelector(state), | ||
| rowData: rowDataSelector(state, props), | ||
| className: classNamesForComponentSelector(state, 'Row'), | ||
| style: stylesForComponentSelector(state, 'Row'), | ||
| })), | ||
| connect( | ||
| (state, props) => ({ | ||
| columnIds: props.selectors.columnIdsSelector(state), | ||
| rowProperties: props.selectors.rowPropertiesSelector(state), | ||
| rowData: props.selectors.rowDataSelector(state, props), | ||
| className: props.selectors.classNamesForComponentSelector(state, 'Row'), | ||
| style: props.selectors.stylesForComponentSelector(state, 'Row'), | ||
| }) | ||
| ), | ||
| mapProps(props => { | ||
| const { components, rowProperties, className, ...otherProps } = props; | ||
| return { | ||
|
|
@@ -35,7 +38,7 @@ const ComposedRowContainer = OriginalComponent => compose( | |
| }), | ||
| )(props => ( | ||
| <OriginalComponent | ||
| {...props} | ||
| {...props} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 -const ComposedRowContainer = OriginalComponent => compose(
+const ComposedRowContainer = compose(
...
-)(props => <OriginalComponent {...props} />);
+); |
||
| /> | ||
| )); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { connect } from '../utils/griddleConnect'; | ||
| import compose from 'recompose/compose'; | ||
| import getContext from 'recompose/getContext'; | ||
| import { textSelector, classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
| import { toggleSettings as toggleSettingsAction } from '../actions'; | ||
|
|
||
| const enhancedSettingsToggle = OriginalComponent => compose( | ||
| getContext({ | ||
| selectors: PropTypes.object | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, and elsewhere, please ensure you have a trailing comma for consistency. |
||
| }), | ||
| connect((state, props) => ({ | ||
| text: textSelector(state, { key: 'settingsToggle' }), | ||
| className: classNamesForComponentSelector(state, 'SettingsToggle'), | ||
| style: stylesForComponentSelector(state, 'SettingsToggle'), | ||
| text: props.selectors.textSelector(state, { key: 'settingsToggle' }), | ||
| className: props.selectors.classNamesForComponentSelector(state, 'SettingsToggle'), | ||
| style: props.selectors.stylesForComponentSelector(state, 'SettingsToggle'), | ||
| }), | ||
| { | ||
| toggleSettings: toggleSettingsAction | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,31 +5,33 @@ import compose from 'recompose/compose'; | |
| import mapProps from 'recompose/mapProps'; | ||
| import getContext from 'recompose/getContext'; | ||
|
|
||
| import { visibleRowIdsSelector, classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
| //import { visibleRowIdsSelector, classNamesForComponentSelector, stylesForComponentSelector } from '../selectors/dataSelectors'; | ||
|
|
||
| const ComposedTableBodyContainer = OriginalComponent => compose( | ||
| getContext({ | ||
| components: PropTypes.object, | ||
| selectors: PropTypes.object, | ||
| }), | ||
| connect((state, props) => ({ | ||
| visibleRowIds: visibleRowIdsSelector(state), | ||
| className: classNamesForComponentSelector(state, 'TableBody'), | ||
| style: stylesForComponentSelector(state, 'TableBody'), | ||
| })), | ||
| connect( | ||
| (state, props) => ({ | ||
| visibleRowIds: props.selectors.visibleRowIdsSelector(state), | ||
| className: props.selectors.classNamesForComponentSelector(state, 'TableBody'), | ||
| style: props.selectors.stylesForComponentSelector(state, 'TableBody'), | ||
| }) | ||
| ), | ||
| mapProps(props => { | ||
| const { components, ...otherProps } = props; | ||
| const { components, selectors, ...otherProps } = props; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed this is the only place you're pulling |
||
| return { | ||
| Row: props.components.Row, | ||
| ...otherProps, | ||
| }; | ||
| }), | ||
| )(({Row, visibleRowIds, style, className}) => ( | ||
| <OriginalComponent | ||
| rowIds={visibleRowIds} | ||
| Row={Row} | ||
| style={style} | ||
| className={className} | ||
| rowIds={visibleRowIds} | ||
| Row={Row} | ||
| style={style} | ||
| className={className} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component can pass-thru )(props => <OriginalComponent {...props} />);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarification: please rename |
||
| /> | ||
| )); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.