Skip to content

Commit

Permalink
Fixes emberjs#14754 deprecate canDispatchToEventMAnager
Browse files Browse the repository at this point in the history
  • Loading branch information
Hassan Abdel-Rahman committed Mar 27, 2017
1 parent 6edfda7 commit 07120ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
38 changes: 2 additions & 36 deletions packages/ember-glimmer/tests/integration/event-dispatcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ moduleFor('EventDispatcher', class extends RenderingTest {
this.registerComponent('x-foo', {
ComponentClass: Component.extend({
click(event) {
assert.notOk(true, 'should not trigger `click` on component');
receivedEvent = event;
},

eventManager: {
click(event) {
receivedEvent = event;
assert.notOk(true, 'should not trigger `click` on eventManager');
}
}
}),
Expand All @@ -61,40 +61,6 @@ moduleFor('EventDispatcher', class extends RenderingTest {
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
}

['@test event manager can re-dispatch to the component'](assert) {
let handlers = [];

this.registerComponent('x-foo', {
ComponentClass: Component.extend({
click() {
handlers.push('component');
},

eventManager: {
click(event, component) {
handlers.push('eventManager');
// Re-dispatch event when you get it.
//
// The second parameter tells the dispatcher
// that this event has been handled. This
// API will clearly need to be reworked since
// multiple eventManagers in a single view
// hierarchy would break, but it shows that
// re-dispatching works
component.$().trigger('click', this);
}
}
}),

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

this.render(`{{x-foo}}`);

this.runTask(() => this.$('#is-done').trigger('click'));
assert.deepEqual(handlers, ['eventManager', 'component']);
}

['@test event handlers are wrapped in a run loop'](assert) {
this.registerComponent('x-foo', {
ComponentClass: Component.extend({
Expand Down
13 changes: 12 additions & 1 deletion packages/ember-views/lib/mixins/view_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,18 @@ export default Mixin.create({
let owner = getOwner(this);
let dispatcher = owner && owner.lookup('event_dispatcher:main');

if (dispatcher && dispatcher.canDispatchToEventManager === null) {
deprecate(
`\`canDispatchToEventManager\` has been deprecated.`,
!('canDispatchToEventManager' in dispatcher),
{
id: 'ember-views.event-dispatcher.canDispatchToEventManager',
until: '3.0.0'
}
);

if (dispatcher &&
'canDispatchToEventManager' in dispatcher &&
dispatcher.canDispatchToEventManager === null) {
dispatcher.canDispatchToEventManager = true;
}
}
Expand Down
12 changes: 11 additions & 1 deletion packages/ember-views/lib/system/event_dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { assign, getOwner } from 'ember-utils';
import { assert } from 'ember-debug';
import { get, set, isNone, run } from 'ember-metal';
import { deprecate } from 'ember-debug';
import { Object as EmberObject } from 'ember-runtime';
import jQuery from './jquery';
import ActionManager from './action_manager';
Expand Down Expand Up @@ -129,13 +130,22 @@ export default EmberObject.extend({
@type boolean
@default false
@since 1.7.0
@deprecated
@private
*/
canDispatchToEventManager: null,

init() {
this._super();
assert('EventDispatcher should never be instantiated in fastboot mode. Please report this as an Ember bug.', environment.hasDOM);

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

/**
Expand Down

0 comments on commit 07120ce

Please sign in to comment.