mirror of
https://github.com/iconify/iconify.git
synced 2025-01-08 07:48:29 +00:00
Do not reuse Promise instance in loadIcon in core
This commit is contained in:
parent
41afe33976
commit
32819127dd
@ -357,15 +357,10 @@ export const loadIcons: IconifyLoadIcons = (
|
|||||||
/**
|
/**
|
||||||
* Cache for loadIcon promises
|
* Cache for loadIcon promises
|
||||||
*/
|
*/
|
||||||
type LoadIconResult = Promise<Required<IconifyIcon>>;
|
export const loadIcon = (
|
||||||
const iconsQueue = Object.create(null) as Record<string, LoadIconResult>;
|
icon: IconifyIconName | string
|
||||||
|
): Promise<Required<IconifyIcon>> => {
|
||||||
export const loadIcon = (icon: IconifyIconName | string): LoadIconResult => {
|
return new Promise((fulfill, reject) => {
|
||||||
if (typeof icon === 'string' && iconsQueue[icon] !== void 0) {
|
|
||||||
return iconsQueue[icon];
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: LoadIconResult = new Promise((fulfill, reject) => {
|
|
||||||
const iconObj = typeof icon === 'string' ? stringToIcon(icon) : icon;
|
const iconObj = typeof icon === 'string' ? stringToIcon(icon) : icon;
|
||||||
loadIcons([iconObj || icon], (loaded) => {
|
loadIcons([iconObj || icon], (loaded) => {
|
||||||
if (loaded.length && iconObj) {
|
if (loaded.length && iconObj) {
|
||||||
@ -380,9 +375,4 @@ export const loadIcon = (icon: IconifyIconName | string): LoadIconResult => {
|
|||||||
reject(icon);
|
reject(icon);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof icon === 'string') {
|
|
||||||
iconsQueue[icon] = result;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user