From f36fcbe2be6546c0b24cbe3e83d0960b82e2a5fc Mon Sep 17 00:00:00 2001 From: Hassan Abdel-Rahman Date: Mon, 27 Mar 2017 16:02:09 -0400 Subject: [PATCH] Fixes #14754 deprecate `canDispatchToEventMAnager` --- .../integration/event-dispatcher-test.js | 29 +++++++++++++++++++ .../ember-views/lib/mixins/view_support.js | 11 ++++++- .../lib/system/event_dispatcher.js | 12 +++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/packages/ember-glimmer/tests/integration/event-dispatcher-test.js b/packages/ember-glimmer/tests/integration/event-dispatcher-test.js index 08b15a79429..abe3b58f698 100644 --- a/packages/ember-glimmer/tests/integration/event-dispatcher-test.js +++ b/packages/ember-glimmer/tests/integration/event-dispatcher-test.js @@ -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; @@ -138,6 +139,34 @@ moduleFor('EventDispatcher#setup', class extends RenderingTest { this.$('div').trigger('myevent'); } + ['@test canDispatchToEventManager is deprecated'](assert) { + this.dispatcher.canDispatchToEventManager = null; + this.registerComponent('x-foo', { + ComponentClass: Component.extend({ + eventManager: { + myEvent() {} + } + }), + template: `

Hello!

` + }); + + 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('
'); this.dispatcher.setup({ myevent: 'myEvent' }, '#app'); diff --git a/packages/ember-views/lib/mixins/view_support.js b/packages/ember-views/lib/mixins/view_support.js index 84257912de3..53412226298 100644 --- a/packages/ember-views/lib/mixins/view_support.js +++ b/packages/ember-views/lib/mixins/view_support.js @@ -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.`, + !('canDispatchToEventManager' in dispatcher), + { + id: 'ember-views.event-dispatcher.canDispatchToEventManager', + until: '3.0.0' + } + ); + + if (dispatcher && !('canDispatchToEventManager' in dispatcher)) { dispatcher.canDispatchToEventManager = true; } } diff --git a/packages/ember-views/lib/system/event_dispatcher.js b/packages/ember-views/lib/system/event_dispatcher.js index 28d86a03162..65d8713cc8f 100644 --- a/packages/ember-views/lib/system/event_dispatcher.js +++ b/packages/ember-views/lib/system/event_dispatcher.js @@ -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'; @@ -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.`, + !('canDispatchToEventManager' in this), + { + id: 'ember-views.event-dispatcher.canDispatchToEventManager', + until: '3.0.0' + } + ); }, /**