Skip to content

Commit

Permalink
Work around IE11 not supported WeakSet by (mis-)using a WeakMap for l…
Browse files Browse the repository at this point in the history
…azy event setup
  • Loading branch information
simonihmig committed Dec 4, 2020
1 parent 876f91c commit 7abe717
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import {
IS_DISPATCHING_ATTRS,
} from './component-managers/curly';

let lazyEventsProcessed = new WeakMap<EventDispatcher, WeakSet<any>>();
// Keep track of which component classes have already been processed for lazy event setup.
// Using a WeakSet would be more appropriate here, but this can only be used when IE11 support is dropped.
// Thus the workaround using a WeakMap<object, true>
let lazyEventsProcessed = new WeakMap<EventDispatcher, WeakMap<object, true>>();

/**
@module @ember/component
Expand Down Expand Up @@ -730,11 +733,9 @@ const Component = CoreView.extend(

let eventDispatcher = this._dispatcher;
if (eventDispatcher) {
let lazyEventsProcessedForComponentClass:
| WeakSet<any>
| undefined = lazyEventsProcessed.get(eventDispatcher);
let lazyEventsProcessedForComponentClass = lazyEventsProcessed.get(eventDispatcher);
if (!lazyEventsProcessedForComponentClass) {
lazyEventsProcessedForComponentClass = new WeakSet();
lazyEventsProcessedForComponentClass = new WeakMap<object, true>();
lazyEventsProcessed.set(eventDispatcher, lazyEventsProcessedForComponentClass);
}

Expand All @@ -748,7 +749,7 @@ const Component = CoreView.extend(
}
});

lazyEventsProcessedForComponentClass.add(proto);
lazyEventsProcessedForComponentClass.set(proto, true);
}
}

Expand Down

0 comments on commit 7abe717

Please sign in to comment.