Skip to content

Commit

Permalink
refactor(icon-service): simplify family initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonoff committed Sep 28, 2021
1 parent e95d257 commit 02de7a8
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions projects/igniteui-angular/src/lib/icon/icon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,6 @@ export class IgxIconService {
return req;
}

/**
* @hidden
*/
private getOrCreateIconFamily(name: string) {
let family: Map<string, string>;

if(this._cachedSvgIcons.has(name)) {
family = this._cachedSvgIcons.get(name) as Map<string, string>;
} else {
family = new Map<string, string>();
this._cachedSvgIcons.set(name, family);
}

return family;
}

/**
* @hidden
*/
Expand All @@ -207,13 +191,14 @@ export class IgxIconService {
div.innerHTML = value;
const svg = div.querySelector('svg') as SVGElement;

if(svg) {
if (!this._cachedSvgIcons.has(family)) {
this._cachedSvgIcons.set(family, new Map<string, string>());
}

if (svg) {
svg.setAttribute('fit', '');
svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
const svgText = svg.outerHTML;

const familyRegistry = this.getOrCreateIconFamily(family);
familyRegistry.set(name, svgText);
this._cachedSvgIcons.get(family).set(name, svg.outerHTML);
}
}
}
Expand Down

0 comments on commit 02de7a8

Please sign in to comment.