Skip to content

Commit

Permalink
only remove unused css
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 1, 2017
1 parent 16692ae commit b73558a
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class DecorationRule {
removeCSSRulesContainingSelector(this.labelClassName, element);
removeCSSRulesContainingSelector(this.badgeClassName, element);
}

isUnused(): boolean {
return !document.querySelector(`.${this.labelClassName}`) && !document.querySelector(`.${this.badgeClassName}`);
}
}

class DecorationStyles {
Expand Down Expand Up @@ -160,15 +164,17 @@ class DecorationStyles {
}
this._decorationRules.forEach((value, index) => {
const { data } = value;
let remove: boolean;
if (Array.isArray(data)) {
remove = data.some(data => !usedDecorations.has(DecorationRule.keyOf(data)));
} else if (!usedDecorations.has(DecorationRule.keyOf(data))) {
remove = true;
}
if (remove) {
value.removeCSSRules(this._styleElement);
this._decorationRules.delete(index);
if (value.isUnused()) {
let remove: boolean;
if (Array.isArray(data)) {
remove = data.some(data => !usedDecorations.has(DecorationRule.keyOf(data)));
} else if (!usedDecorations.has(DecorationRule.keyOf(data))) {
remove = true;
}
if (remove) {
value.removeCSSRules(this._styleElement);
this._decorationRules.delete(index);
}
}
});
}
Expand Down

0 comments on commit b73558a

Please sign in to comment.