Skip to content

Commit

Permalink
Fix IE11: Object.entries is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Feb 26, 2021
1 parent 4cb7da4 commit 403d9a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import InternalComponent, {
handleDeprecatedEventArguments,
InternalComponentConstructor,
jQueryEventShim,
ObjectEntries,
} from './internal';

const UNINITIALIZED: unknown = Object.freeze({});
Expand Down Expand Up @@ -302,7 +303,7 @@ export function handleDeprecatedFeatures(

handleDeprecatedAttributeArguments(target, attributeBindings);

handleDeprecatedEventArguments(target, Object.entries(virtualEvents));
handleDeprecatedEventArguments(target, ObjectEntries(virtualEvents));

{
let superIsVirtualEventListener = prototype['isVirtualEventListener'];
Expand Down
11 changes: 10 additions & 1 deletion packages/@ember/-internals/glimmer/lib/components/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ 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]);
}
})();

export type EventListener = (event: Event) => void;

export default class InternalComponent {
Expand Down Expand Up @@ -444,7 +453,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,
];

Expand Down

0 comments on commit 403d9a4

Please sign in to comment.