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

DropZone: ES6ify (preparing for React 15 upgrade) #5383

Merged
merged 1 commit into from
May 14, 2016

Conversation

ockham
Copy link
Contributor

@ockham ockham commented May 13, 2016

Motivation is to turn it into an ES6 class, which allows us to drop
__reactAutoBindMap in the test and stub prototype methods directly.
Required for the React 15 upgrade which drops __reactAutoBindMap.
(See #5116 for the upgrade PR.)

To test -- check that the DropZonecomponent works as before (try http://calypso.localhost:3000/devdocs/design/dropzones). Also, make sure that all require( './drop-zone' ) instances now have .default attached, due to the ES6 export. (I only found one occurrence, in MediaDropZone.)

/cc @aduth for review

@ockham ockham self-assigned this May 13, 2016
@ockham ockham force-pushed the update/drop-zone-es6ify branch 3 times, most recently from 608b6e2 to 750c848 Compare May 13, 2016 21:56
@ockham ockham changed the title DropZone: ES6ify DropZone: ES6ify (preparing for React 15 upgrade) May 13, 2016
@ockham ockham added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels May 13, 2016
@@ -8,7 +8,7 @@ var React = require( 'react' ),
* Internal dependencies
*/
var analytics = require( 'lib/analytics' ),
DropZone = require( 'components/drop-zone' ),
DropZone = require( 'components/drop-zone' ).default,
Copy link
Contributor

Choose a reason for hiding this comment

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

This section is small enough that it makes sense to tidy up the imports here instead. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True :-) Amended the commit.

@gwwar
Copy link
Contributor

gwwar commented May 13, 2016

:shipit:

@gwwar gwwar added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels May 13, 2016
Motivation is turning it into an ES6 class, which allows us to drop
`__reactAutoBindMap` in the test and stub prototype methods directly.
Required for the React 15 upgrade which drops `__reactAutoBindMap`.
@ockham ockham force-pushed the update/drop-zone-es6ify branch from 750c848 to b742b47 Compare May 14, 2016 11:31
@ockham
Copy link
Contributor Author

ockham commented May 14, 2016

Thanks for reviewing!

@ockham ockham merged commit 6f000f4 into master May 14, 2016
@ockham ockham deleted the update/drop-zone-es6ify branch May 14, 2016 11:36
@ockham ockham mentioned this pull request May 16, 2016
2 tasks
componentDidMount: function() {
// Bind listeners found in componentDidMount(), except for the ones whose
// implementation doesn't refer to `this`.
this.onDrop = this.onDrop.bind( this );
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not something I've seen much conventions around, but do you think there's any value in preserving the original unbound functions and naming these differently? In newer components, I've started assigning them as this.boundFoo = this.foo.bind( this );, but I suppose there's rarely a case for needing the original (prefixing does help to indicate that it's a bound function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found https://facebook.github.io/react/docs/reusable-components.html#no-autobinding, which is what I'm following here.

Since this is a refactoring, I wanted to keep method names so I wouldn't have to worry about the component's consumers.

but I suppose there's rarely a case for needing the original (prefixing does help to indicate that it's a bound function).

Yeah -- in old-style React components, the auto-binding would've overridden the original ones in all practical cases while keeping the original name. Not sure there's much value in keeping the original methods around since even with tests, the this bind seems to make only sense -- any practical examples for using the unbound methods you can think of?

Copy link
Contributor

Choose a reason for hiding this comment

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

any practical examples for using the unbound methods you can think of?

No, not off the top of my head. And even if there were, I suppose it could be as simple as applying another bind to the already-bound function?

I wasn't aware of the React documentation including that as an example, and you make a good point that this replicates the behavior of React.createClass. Then again, one could argue that the behavior of React.createClass is not one that should be replicated 😄 (given that it's not obvious at a glance how the functions are bound)

@aduth
Copy link
Contributor

aduth commented May 16, 2016

Delayed review, but looks good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants