Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(icon): remove unused arguments #1987

Merged
merged 1 commit into from
Jan 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/lib/icon/icon-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'rxjs/add/operator/catch';
/** Exception thrown when attempting to load an icon with a name that cannot be found. */
export class MdIconNameNotFoundError extends MdError {
constructor(iconName: string) {
super(`Unable to find icon with the name "${iconName}"`);
super(`Unable to find icon with the name "${iconName}"`);
}
}

Expand All @@ -25,7 +25,7 @@ export class MdIconNameNotFoundError extends MdError {
*/
export class MdIconSvgTagNotFoundError extends MdError {
constructor() {
super('<svg> tag not found');
super('<svg> tag not found');
}
}

Expand Down Expand Up @@ -248,7 +248,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 @@ -263,7 +263,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 @@ -273,15 +273,15 @@ export class MdIconRegistry {
private _loadSvgIconSetFromConfig(config: SvgIconConfig): Observable<SVGElement> {
// TODO: Document that icons should only be loaded from trusted sources.
return this._fetchUrl(config.url)
.map((svgText) => this._svgElementFromString(svgText));
.map(svgText => this._svgElementFromString(svgText));
}

/**
* 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 @@ -290,16 +290,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 @@ -309,7 +308,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 @@ -320,7 +319,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 @@ -330,7 +329,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 @@ -369,6 +368,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;
}