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

[DEPRECATION] #14754 deprecate canDispatchToEventManager #15078

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 29 additions & 0 deletions packages/ember-glimmer/tests/integration/event-dispatcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
run
} from 'ember-metal';
import { EMBER_IMPROVED_INSTRUMENTATION } from 'ember/features';
import { EventDispatcher } from 'ember-views';

let canDataTransfer = !!document.createEvent('HTMLEvents').dataTransfer;

Expand Down Expand Up @@ -138,6 +139,34 @@ moduleFor('EventDispatcher#setup', class extends RenderingTest {
this.$('div').trigger('myevent');
}

['@test canDispatchToEventManager is deprecated'](assert) {
this.dispatcher.canDispatchToEventManager = null;
Copy link
Member

Choose a reason for hiding this comment

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

In theory, we should not need to force this to be null in this test, the default of undefined should be enough

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

expectDeprecation(() => {
this.render(`{{x-foo}}`);
}, '[DEPRECATED] `canDispatchToEventManager` has been deprecated.');

this.$('div').trigger('myevent');
}

['@test canDispatchToEventManager is deprecated in EventDispatcher'](assert) {
let MyDispatcher = EventDispatcher.extend({
canDispatchToEventManager: null
});

expectDeprecation(() => {
MyDispatcher.create();
}, '[DEPRECATED] `canDispatchToEventManager` has been deprecated.');
}

['@test a rootElement can be specified'](assert) {
this.$().append('<div id="app"></div>');
this.dispatcher.setup({ myevent: 'myEvent' }, '#app');
Expand Down
11 changes: 10 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,16 @@ export default Mixin.create({
let owner = getOwner(this);
let dispatcher = owner && owner.lookup('event_dispatcher:main');

if (dispatcher && dispatcher.canDispatchToEventManager === null) {
deprecate(
`[DEPRECATED] \`canDispatchToEventManager\` has been deprecated.`,
Copy link
Member

Choose a reason for hiding this comment

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

Let's have this message mention eventManager instead of canDispatchToEventManager, and also add the ${this} to the interpolation (so it's clear to someone seeing the deprecation which component caused it.

!('canDispatchToEventManager' in dispatcher),
{
id: 'ember-views.event-dispatcher.canDispatchToEventManager',
until: '3.0.0'
Copy link
Member

Choose a reason for hiding this comment

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

Let's change this to 2.16.0

}
);

if (dispatcher && !('canDispatchToEventManager' in dispatcher)) {
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(
`[DEPRECATED] \`canDispatchToEventManager\` has been deprecated.`,
Copy link
Member

Choose a reason for hiding this comment

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

Let's mention which file this is in.

Copy link
Member

Choose a reason for hiding this comment

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

Also, you should not need to prefix the message with [DEPRECATED]

!('canDispatchToEventManager' in this),
{
id: 'ember-views.event-dispatcher.canDispatchToEventManager',
until: '3.0.0'
}
);
},

/**
Expand Down