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

Do not allocate an array if no before input events #7691

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/renderers/dom/client/eventPlugins/BeforeInputEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,21 @@ var BeforeInputEventPlugin = {
nativeEvent,
nativeEventTarget
) {
return [
extractCompositionEvent(
topLevelType,
targetInst,
nativeEvent,
nativeEventTarget
),
extractBeforeInputEvent(
topLevelType,
targetInst,
nativeEvent,
nativeEventTarget
),
];
var compose = extractCompositionEvent(
topLevelType,
targetInst,
nativeEvent,
nativeEventTarget
);

var before = extractBeforeInputEvent(
topLevelType,
targetInst,
nativeEvent,
nativeEventTarget
);

return compose && before ? [compose, before] : compose ? compose : before;
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 surprised that changing the return type doesn't break any tests, do you know if there are cases in our test suite that returns [null, null]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[null, null] returns for just about every single event plugin test that executes the EventPluginHub.extractEvents code path.

Quickly scanning (throwing on [null, null]), this is 22 of 24 SimpleEventPlugin tests, 7 of 9 ChangeEvent plugin tests, and a handful of other event system tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, if I'm interpreting the coverage correctly, BeforeInputEventPlugin has pretty weak coverage:

screen shot 2016-09-10 at 2 36 42 pm

screen shot 2016-09-10 at 2 35 50 pm

It's possible this is just really hard to test (keyboard stuff). Looks like neither event types (composition or beforeInput) ever instantiate.

Copy link
Contributor

@aweary aweary Sep 10, 2016

Choose a reason for hiding this comment

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

Got it. This is eventually passed to accumulateInto which accepts either an item or array of items, so it works just fine.

},
};

Expand Down