Skip to content

Commit

Permalink
refactor(icon): remove unused arguments (#1987)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto authored and tinayuangao committed Jan 12, 2017
1 parent e74babc commit 3ed76f5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/lib/icon/icon-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -302,7 +302,7 @@ export class MdIconRegistry {
*/
private _loadSvgIconFromConfig(config: SvgIconConfig): Observable<SVGElement> {
return this._fetchUrl(config.url)
.map(svgText => this._createSvgElementForSingleIcon(svgText, config));
.map(svgText => this._createSvgElementForSingleIcon(svgText));
}

/**
Expand All @@ -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;
}

Expand All @@ -329,16 +329,15 @@ 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;
}
// If the icon node is itself an <svg> node, clone and return it directly. If not, set it as
// the content of a new <svg> node.
if (iconNode.tagName.toLowerCase() == 'svg') {
return this._setSvgAttributes(<SVGElement>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
Expand All @@ -348,7 +347,7 @@ export class MdIconRegistry {
const svg = this._svgElementFromString('<svg></svg>');
// 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);
}

/**
Expand All @@ -359,7 +358,7 @@ export class MdIconRegistry {
// creating an element from an HTML string.
const div = document.createElement('DIV');
div.innerHTML = str;
const svg = <SVGElement>div.querySelector('svg');
const svg = div.querySelector('svg') as SVGElement;
if (!svg) {
throw new MdIconSvgTagNotFoundError();
}
Expand All @@ -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');
}
Expand Down Expand Up @@ -410,6 +409,6 @@ export class MdIconRegistry {


/** Clones an SVGElement while preserving type information. */
function cloneSvg(svg: SVGElement) {
return <SVGElement> svg.cloneNode(true);
function cloneSvg(svg: SVGElement): SVGElement {
return svg.cloneNode(true) as SVGElement;
}

0 comments on commit 3ed76f5

Please sign in to comment.