From 3ed76f5fde102f2d3b96dd775fee468c63f62fb7 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Thu, 12 Jan 2017 22:23:11 +0100 Subject: [PATCH] refactor(icon): remove unused arguments (#1987) As per the discussion #1539, there are a few places in the icon registry where the config is being passed without actually being used. This change removes those instances and does some minor cleanup. Fixes #1539. --- src/lib/icon/icon-registry.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/lib/icon/icon-registry.ts b/src/lib/icon/icon-registry.ts index 053abbd78b00..bea95e419fa7 100644 --- a/src/lib/icon/icon-registry.ts +++ b/src/lib/icon/icon-registry.ts @@ -287,7 +287,7 @@ export class MdIconRegistry { for (let i = iconSetConfigs.length - 1; i >= 0; i--) { const config = iconSetConfigs[i]; if (config.svgElement) { - const foundIcon = this._extractSvgIconFromSet(config.svgElement, iconName, config); + const foundIcon = this._extractSvgIconFromSet(config.svgElement, iconName); if (foundIcon) { return foundIcon; } @@ -302,7 +302,7 @@ export class MdIconRegistry { */ private _loadSvgIconFromConfig(config: SvgIconConfig): Observable { return this._fetchUrl(config.url) - .map(svgText => this._createSvgElementForSingleIcon(svgText, config)); + .map(svgText => this._createSvgElementForSingleIcon(svgText)); } /** @@ -318,9 +318,9 @@ export class MdIconRegistry { /** * Creates a DOM element from the given SVG string, and adds default attributes. */ - private _createSvgElementForSingleIcon(responseText: string, config: SvgIconConfig): SVGElement { + private _createSvgElementForSingleIcon(responseText: string): SVGElement { const svg = this._svgElementFromString(responseText); - this._setSvgAttributes(svg, config); + this._setSvgAttributes(svg); return svg; } @@ -329,8 +329,7 @@ export class MdIconRegistry { * tag matches the specified name. If found, copies the nested element to a new SVG element and * returns it. Returns null if no matching element is found. */ - private _extractSvgIconFromSet( - iconSet: SVGElement, iconName: string, config: SvgIconConfig): SVGElement { + private _extractSvgIconFromSet(iconSet: SVGElement, iconName: string): SVGElement { const iconNode = iconSet.querySelector('#' + iconName); if (!iconNode) { return null; @@ -338,7 +337,7 @@ export class MdIconRegistry { // If the icon node is itself an node, clone and return it directly. If not, set it as // the content of a new node. if (iconNode.tagName.toLowerCase() == 'svg') { - return this._setSvgAttributes(iconNode.cloneNode(true), config); + return this._setSvgAttributes(iconNode.cloneNode(true) as SVGElement); } // createElement('SVG') doesn't work as expected; the DOM ends up with // the correct nodes, but the SVG content doesn't render. Instead we @@ -348,7 +347,7 @@ export class MdIconRegistry { const svg = this._svgElementFromString(''); // Clone the node so we don't remove it from the parent icon set element. svg.appendChild(iconNode.cloneNode(true)); - return this._setSvgAttributes(svg, config); + return this._setSvgAttributes(svg); } /** @@ -359,7 +358,7 @@ export class MdIconRegistry { // creating an element from an HTML string. const div = document.createElement('DIV'); div.innerHTML = str; - const svg = div.querySelector('svg'); + const svg = div.querySelector('svg') as SVGElement; if (!svg) { throw new MdIconSvgTagNotFoundError(); } @@ -369,7 +368,7 @@ export class MdIconRegistry { /** * Sets the default attributes for an SVG element to be used as an icon. */ - private _setSvgAttributes(svg: SVGElement, config: SvgIconConfig): SVGElement { + private _setSvgAttributes(svg: SVGElement): SVGElement { if (!svg.getAttribute('xmlns')) { svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); } @@ -410,6 +409,6 @@ export class MdIconRegistry { /** Clones an SVGElement while preserving type information. */ -function cloneSvg(svg: SVGElement) { - return svg.cloneNode(true); +function cloneSvg(svg: SVGElement): SVGElement { + return svg.cloneNode(true) as SVGElement; }