diff --git a/packages/@ember/-internals/glimmer/lib/components/abstract-input.ts b/packages/@ember/-internals/glimmer/lib/components/abstract-input.ts index 0e8ad503e2f..13096945949 100644 --- a/packages/@ember/-internals/glimmer/lib/components/abstract-input.ts +++ b/packages/@ember/-internals/glimmer/lib/components/abstract-input.ts @@ -15,6 +15,8 @@ import InternalComponent, { handleDeprecatedEventArguments, InternalComponentConstructor, jQueryEventShim, + ObjectEntries, + ObjectValues, } from './internal'; const UNINITIALIZED: unknown = Object.freeze({}); @@ -302,7 +304,7 @@ export function handleDeprecatedFeatures( handleDeprecatedAttributeArguments(target, attributeBindings); - handleDeprecatedEventArguments(target, Object.entries(virtualEvents)); + handleDeprecatedEventArguments(target, ObjectEntries(virtualEvents)); { let superIsVirtualEventListener = prototype['isVirtualEventListener']; @@ -316,7 +318,7 @@ export function handleDeprecatedFeatures( listener: Function ): listener is VirtualEventListener { return ( - Object.values(virtualEvents).indexOf(name) !== -1 || + ObjectValues(virtualEvents).indexOf(name) !== -1 || superIsVirtualEventListener.call(this, name, listener) ); }, diff --git a/packages/@ember/-internals/glimmer/lib/components/internal.ts b/packages/@ember/-internals/glimmer/lib/components/internal.ts index b30bc75812c..1942dbe344f 100644 --- a/packages/@ember/-internals/glimmer/lib/components/internal.ts +++ b/packages/@ember/-internals/glimmer/lib/components/internal.ts @@ -28,6 +28,24 @@ import InternalModifier, { InternalModifierManager } from '../modifiers/internal function NOOP(): void {} +// TODO: remove me when IE11 support is EOL +export let ObjectEntries = ((): typeof Object['entries'] => { + if (typeof Object.entries === 'function') { + return Object.entries; + } else { + return (obj: {}) => Object.keys(obj).map((key) => [key, obj[key]] as [string, unknown]); + } +})(); + +// TODO: remove me when IE11 support is EOL +export let ObjectValues = ((): typeof Object['values'] => { + if (typeof Object.values === 'function') { + return Object.values; + } else { + return (obj: {}) => Object.keys(obj).map((key) => obj[key]); + } +})(); + export type EventListener = (event: Event) => void; export default class InternalComponent { @@ -418,7 +436,7 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) { name: string ): boolean { let events = [ - ...Object.values(getEventsMap(this.owner)), + ...ObjectValues(getEventsMap(this.owner)), 'focus-in', 'focus-out', 'key-press', @@ -444,7 +462,7 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) { let { element, component, listenerFor, listeners } = this; let entries: [event: string, argument: string][] = [ - ...Object.entries(getEventsMap(this.owner)), + ...ObjectEntries(getEventsMap(this.owner)), ...extraEvents, ]; @@ -463,7 +481,7 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) { remove(): void { let { element, listeners } = this; - for (let [event, listener] of Object.entries(listeners)) { + for (let [event, listener] of ObjectEntries(listeners)) { element.removeEventListener(event, listener); } diff --git a/packages/@ember/-internals/views/lib/system/event_dispatcher.js b/packages/@ember/-internals/views/lib/system/event_dispatcher.js index 176a4b34356..39b5798fda7 100644 --- a/packages/@ember/-internals/views/lib/system/event_dispatcher.js +++ b/packages/@ember/-internals/views/lib/system/event_dispatcher.js @@ -121,18 +121,8 @@ export default EmberObject.extend({ init() { this._super(); - - assert( - 'EventDispatcher should never be instantiated in fastboot mode. Please report this as an Ember bug.', - (() => { - let owner = getOwner(this); - let environment = owner.lookup('-environment:main'); - - return environment.isInteractive; - })() - ); - this._eventHandlers = Object.create(null); + this._didSetup = false; }, /** @@ -148,6 +138,16 @@ export default EmberObject.extend({ @param addedEvents {Object} */ setup(addedEvents, _rootElement) { + assert( + 'EventDispatcher should never be setup in fastboot mode. Please report this as an Ember bug.', + (() => { + let owner = getOwner(this); + let environment = owner.lookup('-environment:main'); + + return environment.isInteractive; + })() + ); + let events = (this._finalEvents = assign({}, get(this, 'events'), addedEvents)); if (_rootElement !== undefined && _rootElement !== null) { @@ -230,6 +230,8 @@ export default EmberObject.extend({ this.setupHandler(rootElement, event, events[event]); } } + + this._didSetup = true; }, /** @@ -432,6 +434,10 @@ export default EmberObject.extend({ }, destroy() { + if (this._didSetup === false) { + return; + } + let rootElementSelector = get(this, 'rootElement'); let rootElement; if (rootElementSelector.nodeType) { diff --git a/packages/@ember/canary-features/index.ts b/packages/@ember/canary-features/index.ts index 730e9360b16..710f28132b7 100644 --- a/packages/@ember/canary-features/index.ts +++ b/packages/@ember/canary-features/index.ts @@ -18,7 +18,7 @@ export const DEFAULT_FEATURES = { EMBER_NAMED_BLOCKS: true, EMBER_GLIMMER_HELPER_MANAGER: true, EMBER_GLIMMER_INVOKE_HELPER: true, - EMBER_MODERNIZED_BUILT_IN_COMPONENTS: null, + EMBER_MODERNIZED_BUILT_IN_COMPONENTS: true, EMBER_STRICT_MODE: true, EMBER_DYNAMIC_HELPERS_AND_MODIFIERS: null, };