Skip to content

Commit

Permalink
[CLEANUP beta] Remove custom eventManager support.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jan 10, 2018
1 parent fde777c commit 107be09
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 162 deletions.
62 changes: 0 additions & 62 deletions packages/ember-glimmer/tests/integration/event-dispatcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,6 @@ moduleFor('EventDispatcher', class extends RenderingTest {
assert.notOk(hasReceivedEvent, 'change event has not been received');
}

['@test dispatches to the nearest event manager'](assert) {
let receivedEvent;

this.registerComponent('x-foo', {
ComponentClass: Component.extend({
click() {
assert.notOk(true, 'should not trigger `click` on component');
},

eventManager: {
click(event) {
receivedEvent = event;
}
}
}),

template: `<input id="is-done" type="checkbox">`
});


expectDeprecation(/`eventManager` has been deprecated/);
this.render(`{{x-foo}}`);

this.runTask(() => this.$('#is-done').trigger('click'));
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
}

['@test event handlers are wrapped in a run loop'](assert) {
this.registerComponent('x-foo', {
ComponentClass: Component.extend({
Expand Down Expand Up @@ -160,20 +133,6 @@ moduleFor('EventDispatcher#setup', class extends RenderingTest {
this.$('div').trigger('myevent');
}

['@test eventManager is deprecated']() {
this.registerComponent('x-foo', {
ComponentClass: Component.extend({
eventManager: {
myEvent() {}
}
}),
template: `<p>Hello!</p>`
});

expectDeprecation(/`eventManager` has been deprecated/);
this.render(`{{x-foo}}`);
}

['@test a rootElement can be specified'](assert) {
this.element.innerHTML = '<div id="app"></div>';
// this.$().append('<div id="app"></div>');
Expand Down Expand Up @@ -217,27 +176,6 @@ moduleFor('EventDispatcher#setup', class extends RenderingTest {
}
});

moduleFor('custom EventDispatcher subclass with #setup', class extends RenderingTest {
constructor() {
super();

let dispatcher = this.owner.lookup('event_dispatcher:main');
run(dispatcher, 'destroy');
this.owner.__container__.reset('event_dispatcher:main');
this.owner.unregister('event_dispatcher:main');
}

['@test canDispatchToEventManager is deprecated in EventDispatcher']() {
let MyDispatcher = EventDispatcher.extend({
canDispatchToEventManager: null
});
this.owner.register('event_dispatcher:main', MyDispatcher);

expectDeprecation(/`canDispatchToEventManager` has been deprecated/);
this.owner.lookup('event_dispatcher:main');
}
});

if (EMBER_IMPROVED_INSTRUMENTATION) {
moduleFor('EventDispatcher - Instrumentation', class extends RenderingTest {
teardown() {
Expand Down
21 changes: 0 additions & 21 deletions packages/ember-views/lib/mixins/view_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,27 +415,6 @@ 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');

deprecate(
`\`eventManager\` has been deprecated in ${this}.`,
false,
{
id: 'ember-views.event-dispatcher.canDispatchToEventManager',
until: '2.17.0'
}
);

if (dispatcher && !('canDispatchToEventManager' in dispatcher)) {
dispatcher.canDispatchToEventManager = true;
}
}

if (environment._ENABLE_DID_INIT_ATTRS_SUPPORT) {
deprecate(
`[DEPRECATED] didInitAttrs called in ${this.toString()}.`,
Expand Down
83 changes: 4 additions & 79 deletions packages/ember-views/lib/system/event_dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,6 @@ export default EmberObject.extend({
*/
rootElement: 'body',

/**
It enables events to be dispatched to the view's `eventManager.` When present,
this object takes precedence over handling of events on the view itself.
Note that most Ember applications do not use this feature. If your app also
does not use it, consider setting this property to false to gain some performance
improvement by allowing the EventDispatcher to skip the search for the
`eventManager` on the view tree.
```javascript
let EventDispatcher = Em.EventDispatcher.extend({
events: {
click : 'click',
focusin : 'focusIn',
focusout : 'focusOut',
change : 'change'
},
canDispatchToEventManager: false
});
container.register('event_dispatcher:main', EventDispatcher);
```
@property canDispatchToEventManager
@type boolean
@default false
@since 1.7.0
@deprecated
@private
*/

init() {
this._super();

Expand All @@ -143,15 +113,6 @@ export default EmberObject.extend({
return environment.isInteractive;
})());

deprecate(
`\`canDispatchToEventManager\` has been deprecated in ${this}.`,
!('canDispatchToEventManager' in this),
{
id: 'ember-views.event-dispatcher.canDispatchToEventManager',
until: '2.17.0'
}
);

this._eventHandlers = Object.create(null);
},

Expand Down Expand Up @@ -246,16 +207,12 @@ export default EmberObject.extend({
}

if (HAS_JQUERY) {
rootElement.on(`${event}.ember`, '.ember-view', function(evt, triggeringManager) {
rootElement.on(`${event}.ember`, '.ember-view', function(evt) {
let view = viewRegistry[this.id];
let result = true;

let manager = self.canDispatchToEventManager ? self._findNearestEventManager(view, eventName) : null;

if (manager && manager !== triggeringManager) {
result = self._dispatchEvent(manager, evt, eventName, view);
} else if (view) {
result = self._bubbleEvent(view, evt, eventName);
if (view) {
result = view.handleEvent(eventName, evt);
}

return result;
Expand Down Expand Up @@ -291,7 +248,7 @@ export default EmberObject.extend({
let result = true;

if (view) {
result = this._bubbleEvent(view, event, eventName);
result = view.handleEvent(eventName, event);
}

return result;
Expand Down Expand Up @@ -367,38 +324,6 @@ export default EmberObject.extend({
return viewRegistry;
},

_findNearestEventManager(view, eventName) {
let manager = null;

while (view) {
manager = get(view, 'eventManager');
if (manager && manager[eventName]) { break; }

view = get(view, 'parentView');
}

return manager;
},

_dispatchEvent(object, evt, eventName, view) {
let result = true;

let handler = object[eventName];
if (typeof handler === 'function') {
result = run(object, handler, evt, view);
// Do not preventDefault in eventManagers.
evt.stopPropagation();
} else {
result = this._bubbleEvent(view, evt, eventName);
}

return result;
},

_bubbleEvent(view, evt, eventName) {
return view.handleEvent(eventName, evt);
},

destroy() {
let rootElementSelector = get(this, 'rootElement');
let rootElement;
Expand Down

0 comments on commit 107be09

Please sign in to comment.