Skip to content

Commit

Permalink
Add mini fill for creating the base argument in the Set constructor `…
Browse files Browse the repository at this point in the history
…Set(base)` for IE11. This simply copies properties from the old set.
  • Loading branch information
Steven Orvell committed Feb 9, 2017
1 parent 314234a commit ef69503
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/utils/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
p.mozMatchesSelector || p.msMatchesSelector ||
p.oMatchesSelector || p.webkitMatchesSelector;

// unique global id for deduping mixins.
let dedupeId = 0;

Polymer.Utils = {

/**
Expand Down Expand Up @@ -110,17 +113,22 @@
*/
dedupingMixin(mixin) {
mixin = this.cachingMixin(mixin);
// maintain a unique id for each mixin
if (!mixin.__id) {
mixin.__dedupeId = ++dedupeId;
}
return function(base) {
let baseSet = base.__mixinSet;
if (baseSet && baseSet.has(mixin)) {
if (baseSet && baseSet[mixin.__dedupeId]) {
return base;
}
let extended = mixin(base);
// copy inherited mixin set from the extended class, or the base class
// NOTE: the caching mixin may return exactly the same class as given,
// but copying the Set seems cheaper than using hasOwnProperty on the extended class
extended.__mixinSet = new Set(extended.__mixinSet || baseSet);
extended.__mixinSet.add(mixin);
// NOTE: we avoid use of Set here because some browser (IE11)
// cannot extend a base Set via the constructor.
extended.__mixinSet =
Object.create(extended.__mixinSet || baseSet || null);
extended.__mixinSet[mixin.__dedupeId] = true;
return extended;
}
},
Expand Down

0 comments on commit ef69503

Please sign in to comment.