fix(map): global map

This commit is contained in:
Manu Mtz.-Almeida
2018-12-12 22:28:01 +01:00
parent 3b3e212517
commit 03bea5cfb4
4 changed files with 24 additions and 8 deletions
-2
View File
@@ -25,7 +25,6 @@ export namespace Components {
* A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property.
*/
'icon'?: string;
'iconMap'?: {[name: string]: string};
/**
* Specifies which icon to use on `ios` mode.
*/
@@ -68,7 +67,6 @@ export namespace Components {
* A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property.
*/
'icon'?: string;
'iconMap'?: {[name: string]: string};
/**
* Specifies which icon to use on `ios` mode.
*/
+4 -6
View File
@@ -1,5 +1,5 @@
import { Component, Element, Prop, State, Watch } from '@stencil/core';
import { getName, getSrc, isValid } from './utils';
import { getIconMap, getName, getSrc, isValid } from './utils';
@Component({
tag: 'ion-icon',
@@ -20,9 +20,6 @@ export class Icon {
@Prop({ context: 'document' }) doc!: Document;
@Prop({ context: 'window' }) win: any;
/** @internal */
@Prop() iconMap?: {[name: string]: string};
/**
* The color to use for the background of the item.
*/
@@ -167,8 +164,9 @@ export class Icon {
}
private getNamedUrl(name: string) {
if (this.iconMap) {
return this.iconMap[name];
const url = getIconMap().get(name);
if (url) {
return url;
}
return `${this.resourcesUrl}svg/${name}.svg`;
}
+18
View File
@@ -1,4 +1,22 @@
let CACHED_MAP: Map<string, string>;
export function getIconMap(): Map<string, string> {
if (!CACHED_MAP) {
const win = window as any;
win.Ionicons = win.Ionicons || {};
CACHED_MAP = win.Ionicons.map = win.Ionicons.map || new Map();
}
return CACHED_MAP;
}
export function addIcons(icons: {[name: string]: string }) {
const map = getIconMap();
Object.keys(icons).forEach(name => {
map.set(name, icons[name]);
});
}
export function getName(
name: string | undefined,
mode: string | undefined,
+2
View File
@@ -0,0 +1,2 @@
export { addIcons } from './icon/utils';