-
Notifications
You must be signed in to change notification settings - Fork 48.3k
Deprecate 'return false' in event handlers #2039
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
Conversation
@@ -34,4 +34,4 @@ sass: | |||
sass_dir: _css | |||
gems: | |||
- jekyll-redirect-from | |||
react_version: 0.11.1 | |||
react_version: 0.12.0-alpha |
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.
Just leave this alone – docs are built from the 0.11-stable branch and we just won't cherry-pick this in.
* @param {function} Application-level callback. | ||
* @param {string} domID DOM ID to pass to the callback. | ||
*/ | ||
/** |
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 indentation here looks messed up?
if (__DEV__) { | ||
monitorCodeUse('react_event_return_false'); | ||
console.warn( | ||
'Returning `false` from an event handler will be deprecated in a ' + |
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.
one more tweak (sorry): let's say "is deprecated and will be ignored in a future release."
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.
Should it also include === true
? For handler() {return bla.shouldReturnFalse;}
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.
Seems reasonable to me.
@@ -309,6 +310,17 @@ var SimpleEventPlugin = { | |||
*/ | |||
executeDispatch: function(event, listener, domID) { | |||
var returnValue = EventPluginUtils.executeDispatch(event, listener, domID); | |||
if (__DEV__) { | |||
if (typeof returnValue === 'boolean') { | |||
monitorCodeUse('react_event_return_false'); |
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.
Sorry, missed this: internally, this is a different function that logs the message. You'd pass a second parameter, which is an object that contains all you need to know to trace back to this function so that people can act upon it:
monitorCodeUse('react_event_return_false', {eventHandlerName: listener.__reactBoundMethod.displayName});
And maybe some other info, dunno. See #2052
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.
FWIW we already have these in the code:
monitorCodeUse('react_object_map_children');
monitorCodeUse('react_no_scroll_event');
I guess the call stack isn't particularly useful though in this case.
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.
Right, and we don't actually bother tracking these two down. These are only to give an idea of the usage pattern internally.
Nope. Ill just fix that PR and pull it in quick. |
if (__DEV__) { | ||
if (typeof returnValue === 'boolean') { | ||
monitorCodeUse('react_event_return_false', { | ||
eventHandlerName: listener.__reactBoundMethod.displayName |
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.
@crm416 ugh sorry, I derped. This is better as (listener.__reactBoundContext && listener.__reactBoundContext.constructor.displayName) || '<<anonymous>>'
. It makes more sense to go find the displayName
this way, than to look for it on the handler, since the handler can come from a mixin (in which case the method's displayName
is kinda useless no matter how we do it).
So if you change this line to that, it won't depend on the other PR anymore, and I can pull this in.
@chenglou No problem. Should be fixed now. |
if (typeof returnValue === 'boolean') { | ||
var eventHandlerName = (listener.__reactBoundContext && | ||
listener.__reactBoundContext.constructor.displayName) || | ||
'<<anonymous>>'; |
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.
this assignment is really tough to read, and I think is better written with a ternary
var eventHandlerName = listener.__reactBoundContext ?
listener.__reactBoundContext.constructor.displayName :
'<<anonymous>>';
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.
Though I suppose that capture the case where listener.__reactBoundContext.constructor.displayName
is undefined...
var eventHandlerName =
(listener.__reactBoundContext &&
listener.__reactBoundContext.constructor.displayName) ||
'<<anonymous>>';
is slightly better I suppose...
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.
My bad. Also, would a component name be enough? I guess it is?
@zpao Fixed! Thanks. |
@crm416: @sebmarkbage has spoken. You can take out that |
@chenglou No worries-- |
@@ -309,6 +309,16 @@ var SimpleEventPlugin = { | |||
*/ | |||
executeDispatch: function(event, listener, domID) { | |||
var returnValue = EventPluginUtils.executeDispatch(event, listener, domID); | |||
if (__DEV__) { | |||
if (typeof returnValue === 'boolean') { |
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.
There's a warning
module (similar to invariant
. Use that one instead.
I noticed that in |
@sebmarkbage ^ |
Deprecate 'return false' in event handlers
Fixes #2015. Wasn't sure how to handle
react-version
in _config.yml, given that this is a v0.12 milestone.