Skip to content

Commit

Permalink
Disable costly eventManager support when unused.
Browse files Browse the repository at this point in the history
For every event that we observe (which is basically all bubbling events
in the DOM) we would iterate the entire `parentView` structure of the
target elements view looking for an `eventManager` (and then we would
dispatch the event to the `eventManager` instead of the view itself).

This support has existed for a *very* long time, and is generally
unused in most applications. Unfortunately, the iteration upwards through
the view heirarchy is much more costly than we would like. This is
currently being done for events like `mouseenter` and  `mousemove` and
that very very very few applications (if any) actually take advantage of
this support.

This changes the `EventDispatcher` to (by default) disable support for
`eventManager`'s (and avoids the costly `parentView` iteration) until
we actually instantiate a component that has an `eventManager` property.

In the future, we should deprecate specifying an `eventManager`, but this
makes the feature much more "pay as you go".
  • Loading branch information
rwjblue authored and locks committed Dec 25, 2016
1 parent 109ea87 commit 9cbe967
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion packages/ember-views/lib/mixins/view_support.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { guidFor } from 'ember-utils';
import { guidFor, getOwner } from 'ember-utils';
import { assert, deprecate, descriptor, runInDebug, Mixin } from 'ember-metal';
import { environment } from 'ember-environment';
import { matches } from '../system/utils';
Expand Down Expand Up @@ -485,6 +485,18 @@ export default Mixin.create({
this.elementId = guidFor(this);
}

// if we find an `eventManager` property, deopt the
// `EventDispatcher`'s `canDispatchToEventManager` property
// if `null`
if (this.eventManager) {
let owner = getOwner(this);
let dispatcher = owner && owner.lookup('event_dispatcher:main');

if (dispatcher && dispatcher.canDispatchToEventManager === null) {
dispatcher.canDispatchToEventManager = true;
}
}

deprecate(
`[DEPRECATED] didInitAttrs called in ${this.toString()}.`,
typeof(this.didInitAttrs) !== 'function',
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-views/lib/system/event_dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export default EmberObject.extend({
@property canDispatchToEventManager
@type boolean
@default 'true'
@default false
@since 1.7.0
@private
*/
canDispatchToEventManager: true,
canDispatchToEventManager: null,

init() {
this._super();
Expand Down

0 comments on commit 9cbe967

Please sign in to comment.