mirror of
https://github.com/iconify/iconify.git
synced 2024-11-14 00:34:04 +00:00
Use Set to mark icons as missing
This commit is contained in:
parent
59bdbe89e0
commit
7ca4026eb6
@ -70,7 +70,7 @@ export function scanDOM(rootNode?: ObservedNode, addTempNode = false): void {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storage.missing[name]) {
|
if (storage.missing.has(name)) {
|
||||||
return {
|
return {
|
||||||
status: 'missing',
|
status: 'missing',
|
||||||
};
|
};
|
||||||
|
@ -109,7 +109,7 @@ export function updateCallbacks(provider: string, prefix: string): void {
|
|||||||
prefix,
|
prefix,
|
||||||
name,
|
name,
|
||||||
});
|
});
|
||||||
} else if (storage.missing[name] !== void 0) {
|
} else if (storage.missing.has(name)) {
|
||||||
// Missing
|
// Missing
|
||||||
icons.missing.push({
|
icons.missing.push({
|
||||||
provider,
|
provider,
|
||||||
|
@ -186,9 +186,8 @@ function loadNewIcons(provider: string, prefix: string, icons: string[]): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Not found: mark as missing
|
// Not found: mark as missing
|
||||||
const t = Date.now();
|
|
||||||
item.icons.forEach((name) => {
|
item.icons.forEach((name) => {
|
||||||
storage.missing[name] = t;
|
storage.missing.add(name);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Add icons to storage
|
// Add icons to storage
|
||||||
|
@ -72,7 +72,7 @@ export function sortIcons(icons: IconifyIconName[]): SortedIcons {
|
|||||||
let list;
|
let list;
|
||||||
if (localStorage.icons[name] !== void 0) {
|
if (localStorage.icons[name] !== void 0) {
|
||||||
list = result.loaded;
|
list = result.loaded;
|
||||||
} else if (prefix === '' || localStorage.missing[name] !== void 0) {
|
} else if (prefix === '' || localStorage.missing.has(name)) {
|
||||||
// Mark icons without prefix as missing because they cannot be loaded from API
|
// Mark icons without prefix as missing because they cannot be loaded from API
|
||||||
list = result.missing;
|
list = result.missing;
|
||||||
} else {
|
} else {
|
||||||
|
@ -69,7 +69,8 @@ export function getIconData(
|
|||||||
const storage = getStorage(icon.provider, icon.prefix);
|
const storage = getStorage(icon.provider, icon.prefix);
|
||||||
const iconName = icon.name;
|
const iconName = icon.name;
|
||||||
return (
|
return (
|
||||||
storage.icons[iconName] || (storage.missing[iconName] ? null : void 0)
|
storage.icons[iconName] ||
|
||||||
|
(storage.missing.has(iconName) ? null : void 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,16 +7,21 @@ import { quicklyValidateIconSet } from '@iconify/utils/lib/icon-set/validate-bas
|
|||||||
/**
|
/**
|
||||||
* List of icons
|
* List of icons
|
||||||
*/
|
*/
|
||||||
type IconRecords = Record<string, FullIconifyIcon | null>;
|
type IconRecords = Record<string, FullIconifyIcon>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage type
|
* Storage type
|
||||||
*/
|
*/
|
||||||
export interface IconStorage {
|
export interface IconStorage {
|
||||||
|
// Provider and prefix
|
||||||
provider: string;
|
provider: string;
|
||||||
prefix: string;
|
prefix: string;
|
||||||
|
|
||||||
|
// List of available icons
|
||||||
icons: IconRecords;
|
icons: IconRecords;
|
||||||
missing: Record<string, number>;
|
|
||||||
|
// List of missing icons
|
||||||
|
missing: Set<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +40,7 @@ export function newStorage(provider: string, prefix: string): IconStorage {
|
|||||||
provider,
|
provider,
|
||||||
prefix,
|
prefix,
|
||||||
icons: Object.create(null) as IconStorage['icons'],
|
icons: Object.create(null) as IconStorage['icons'],
|
||||||
missing: Object.create(null) as IconStorage['missing'],
|
missing: new Set(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,12 +68,11 @@ export function addIconSet(storage: IconStorage, data: IconifyJSON): string[] {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const t = Date.now();
|
|
||||||
return parseIconSet(data, (name, icon: FullIconifyIcon | null) => {
|
return parseIconSet(data, (name, icon: FullIconifyIcon | null) => {
|
||||||
if (icon) {
|
if (icon) {
|
||||||
storage.icons[name] = icon;
|
storage.icons[name] = icon;
|
||||||
} else {
|
} else {
|
||||||
storage.missing[name] = t;
|
storage.missing.add(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -100,7 +104,7 @@ export function addIconToStorage(
|
|||||||
* Check if icon exists
|
* Check if icon exists
|
||||||
*/
|
*/
|
||||||
export function iconExists(storage: IconStorage, name: string): boolean {
|
export function iconExists(storage: IconStorage, name: string): boolean {
|
||||||
return storage.icons[name] !== void 0;
|
return !!storage.icons[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,7 @@ describe('Testing storage', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Mark 'not-really-missing' as missing
|
// Mark 'not-really-missing' as missing
|
||||||
storage.missing['not-really-missing'] = Date.now();
|
storage.missing.add('not-really-missing');
|
||||||
|
|
||||||
// Add invalid icon
|
// Add invalid icon
|
||||||
addIconToStorage(storage, 'invalid', {} as unknown as IconifyIcon);
|
addIconToStorage(storage, 'invalid', {} as unknown as IconifyIcon);
|
||||||
|
Loading…
Reference in New Issue
Block a user