Skip to content

Conversation

@gaearon
Copy link
Collaborator

@gaearon gaearon commented Sep 1, 2017

It's pretty small but still unnecessary indirection now that we don't support IE8.
See inline comments.

Inline the part that we actually use.
Drop IE8 polyfill and unsubscription code.
Stack still depends on the return value. I just inline this into Stack version since we don't really care about it.

trapBubbledEvent: function(topLevelType, handlerBaseName, handle) {
return ReactDOMEventListener.trapBubbledEvent(
ReactDOMEventListener.trapBubbledEvent(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fiber codebase doesn't use return value (which is always allocating an object).

}
return EventListener.listen(
element,
element.addEventListener(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only case in which this wouldn't be equivalent is if element is truthy but not a DOM node. Doesn't seem like this could happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to throw if element is falsy? I don't think there's any current code path where trapBubbledEvent or trapCaptureEvent should be called without a node.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think EventListener gets shimmed in www?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There exists a mobile version that wraps into TimeSlice guards but we don't use it. At least not since flat bundles. Nobody complained.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about when element is null here too and would +1 an invariant or an action item to investigate this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think an invariant is very valuable here because it's a leaf code path (throws immediately with a very obvious message).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aah, I get it now. We leave fbjs/lib/EventListener import in the www flat bundle, which actually redirects to the internal EventListener fork.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gaearon what throws immediately? If this is protected from null elements earlier in the code path could we just remove the falsy check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@aweary Yes I think we can.

expect(setEventListeners.length).toEqual(dependencies.length);

for (i = 0; i < setEventListeners.length; i++) {
expect(dependencies.indexOf(setEventListeners[i])).toBeTruthy();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I deleted this set of assertions. I'm not sure what they're supposed to be testing but they didn't work in the first place.

The intention was probably to match whether an array contains an item, but toBeTruthy() check passes for -1. And -1 is exactly what we get on master because dependencies array looks like this:

      [ 'topBlur',
        'topChange',
        'topClick',
        'topFocus',
        'topInput',
        'topKeyDown',
        'topKeyUp',
        'topSelectionChange' ]

but value being tested looks like

      'blur'

Maybe there's some better way to test this but I figured just asserting the count is enough.

case 'object':
inst._wrapperState.listeners = [
ReactBrowserEventEmitter.trapBubbledEvent('topLoad', 'load', node),
trapBubbledEvent('topLoad', 'load', node),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Stack code still relies on return value for unsubscribing. Fiber doesn't. I inlined the old Stack-friendly version right into Stack.

Copy link
Contributor

Choose a reason for hiding this comment

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

How does Fiber handle removing those listeners on unmount? Does it just not do that anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it doesn't. Relies on GC to clean them up.

Copy link
Contributor

Choose a reason for hiding this comment

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

At some point I need to circle back about this on #9333. We need local listeners and I'm trying to figure out the best way to clean them up.

@gaearon gaearon requested review from aweary and sophiebits September 1, 2017 18:18
}
for (i = 0; i < captureCalls.length; i++) {
setEventListeners.push(captureCalls[i][1]);
}
Copy link
Collaborator Author

@gaearon gaearon Sep 1, 2017

Choose a reason for hiding this comment

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

Deleted this aggregation because it goes through the same code path now.

@gaearon gaearon changed the title Remove dependency on fbjs/lib/EventListener Remove dependency on fbjs/lib/EventListener and fbjs/lib/focusNode Sep 1, 2017
var AutoFocusUtils = {
focusDOMComponent: function() {
focusNode(ReactDOMComponentTree.getNodeFromInstance(this));
ReactDOMComponentTree.getNodeFromInstance(this).focus();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is Stack-only codepath.

Copy link
Contributor

@nhunzaker nhunzaker left a comment

Choose a reason for hiding this comment

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

Fantastic update, 👍

Copy link
Collaborator

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

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

Don't think the EventListener change is right; see https://fburl.com/8jv38orh. It's important for error logging.

@gaearon
Copy link
Collaborator Author

gaearon commented Sep 1, 2017

Probably abandoning—seems like adding injection to work around internal hijack of EventListener would add more size than having this in the first place.

@gaearon gaearon closed this Sep 1, 2017
@sophiebits
Copy link
Collaborator

We can still get rid of focusNode!

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.

5 participants