From 02de7a831088d54f8b16fe4c986140ba29c36632 Mon Sep 17 00:00:00 2001 From: simeonoff Date: Tue, 28 Sep 2021 20:45:46 +0300 Subject: [PATCH] refactor(icon-service): simplify family initialization --- .../src/lib/icon/icon.service.ts | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/projects/igniteui-angular/src/lib/icon/icon.service.ts b/projects/igniteui-angular/src/lib/icon/icon.service.ts index c2b5f83d804..47a838fa6e5 100644 --- a/projects/igniteui-angular/src/lib/icon/icon.service.ts +++ b/projects/igniteui-angular/src/lib/icon/icon.service.ts @@ -182,22 +182,6 @@ export class IgxIconService { return req; } - /** - * @hidden - */ - private getOrCreateIconFamily(name: string) { - let family: Map; - - if(this._cachedSvgIcons.has(name)) { - family = this._cachedSvgIcons.get(name) as Map; - } else { - family = new Map(); - this._cachedSvgIcons.set(name, family); - } - - return family; - } - /** * @hidden */ @@ -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()); + } + + 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); } } }