-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Remove Mixins #1078
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
Remove Mixins #1078
Conversation
This reverts commit e46a22d.
This reverts commit bfd939d.
This reverts commit 1858fd0.
This reverts commit e8ce7da.
This reverts commit 320b843.
This reverts commit 4c5d43d.
This reverts commit 87521bb.
(ReactDataGrid component adds the MetricsComputatorMixin so mixin methods are available to any child component via the context api, it does not need to be added to the Grid component)
| onHeaderDrop: PropTypes.func | ||
| }, | ||
|
|
||
| mixins: [ColumnUtilsMixin], |
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.
Does not need to add utility functions as a mixin. They can be used directly
| overScan: PropTypes.object | ||
| }, | ||
|
|
||
| mixins: [ |
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.
GridScrollMixin is only used by the Grid component so moved the logic into the Grid component
DOMMetrics.MetricsComputatorMixin defines childContextTypes/getChildContext to implicitly pass metricsComputator through the component tree. ReactDataGrid (Parent) component is using the same mixin and acts as the context provider so Grid component does not need to add it. It can be safely removed
| const ReactDataGrid = createReactClass({ | ||
| displayName: 'ReactDataGrid', | ||
|
|
||
| mixins: [ |
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.
ColumnMetricsMixin is only used by the ReactDataGrid component so moved the logic into the component
DOMMetrics.MetricsComputatorMixin and DOMMetrics.MetricsMixin mixins are used to create a parent child coupling though the unstable context API. The idea is to update children components on window.resize event. The parent component ReactDataGrid maintains a list of components and computator functions and calls metricsUpdated method on each component when the computator function returns a different value. Only two components (ReactDataGrid and Viewport via ViewportScrollMixin) were using this logic and it has been completely removed. The computator logic has been moved to individual components (check resize event handlers)
Some of the KeyboardHandlerMixin functions are moved to keyboardUtils and the remaining functions are moved into the component
|
|
||
| const Viewport = createReactClass({ | ||
| displayName: 'Viewport', | ||
| mixins: [ViewportScroll], |
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.
ViewportScroll helper functions are moved to viewportUtils and the remaining methods are copied into the Viewport component
|
Nice, a great step towards modernizing this towards React 16 and beyond. This should resolve the remaining requirements for moving out of I'm not sure what tests would be needed for this change though, since all existing behavior should remain the same. |
malonecj
left a comment
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.
The strategy here looks good - I am keen to get this in. Perhaps we can add some tests around the utility functions that we migrated. Apart from that I think we are good to go
|
@malonecj added unit tests for the utility functions |
| expect(shim.style.width).toBe('5px'); | ||
| expect(shim.style.height).toBe('10px'); | ||
| expect(shim.className.indexOf('react-grid-ScrollShim')).not.toBe(-1); | ||
| }); |
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.
👍
…class instead of strict equality
|
Awesome work on this one @amanmahajan7. One step closer to React 16 |
Description
A few sentences describing the overall goals of the pull request's commits.
Migration strategies:
https://reactjs.org/blog/2016/07/13/mixins-considered-harmful.html#migrating-from-mixins
Use utility functions when possible
If there is just one component using
mixinthen embed themixinlogic right into the componentHigher Order Components are tricky to use as
refsare used in many placesRemove mixins
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")
What is the current behavior? (You can also link to an open issue here)
What is the new behavior?
Does this PR introduce a breaking change? (check one with "x")
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...
Other information: