mirror of
https://github.com/iconify/iconify.git
synced 2024-12-12 13:47:49 +00:00
Optimisations in core
This commit is contained in:
parent
780f93c7a0
commit
aebed6433d
@ -49,7 +49,7 @@ export function updateCallbacks(storage: IconStorageWithAPI): void {
|
||||
}
|
||||
|
||||
const name = icon.name;
|
||||
if (storage.icons[name] !== void 0) {
|
||||
if (storage.icons[name]) {
|
||||
// Loaded
|
||||
icons.loaded.push({
|
||||
provider,
|
||||
|
@ -109,35 +109,45 @@ export function mockAPIData(data: IconifyMockAPI): void {
|
||||
switch (data.type) {
|
||||
case 'icons': {
|
||||
const provider = data.provider;
|
||||
if (iconsStorage[provider] === void 0) {
|
||||
iconsStorage[provider] = {};
|
||||
}
|
||||
const providerStorage = iconsStorage[provider];
|
||||
|
||||
const prefix = data.prefix;
|
||||
if (providerStorage[prefix] === void 0) {
|
||||
providerStorage[prefix] = [];
|
||||
}
|
||||
|
||||
iconsStorage[provider][prefix].push(data);
|
||||
const providerStorage =
|
||||
iconsStorage[provider] ||
|
||||
(iconsStorage[provider] = Object.create(null) as Record<
|
||||
string,
|
||||
IconifyMockIconsAPI[]
|
||||
>);
|
||||
|
||||
(providerStorage[prefix] || (providerStorage[prefix] = [])).push(
|
||||
data
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'custom': {
|
||||
const provider = data.provider;
|
||||
if (customProviderStorage[provider] === void 0) {
|
||||
customProviderStorage[provider] = {};
|
||||
}
|
||||
customProviderStorage[provider][data.uri] = data;
|
||||
|
||||
const providerStorage =
|
||||
customProviderStorage[provider] ||
|
||||
(customProviderStorage[provider] = Object.create(
|
||||
null
|
||||
) as Record<string, IconifyMockCustomAPI>);
|
||||
|
||||
providerStorage[data.uri] = data;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'host': {
|
||||
const host = data.host;
|
||||
if (customHostStorage[host] === void 0) {
|
||||
customHostStorage[host] = {};
|
||||
}
|
||||
customHostStorage[host][data.uri] = data;
|
||||
|
||||
const hostStorage =
|
||||
customHostStorage[host] ||
|
||||
(customHostStorage[host] = Object.create(null) as Record<
|
||||
string,
|
||||
IconifyMockCustomHostAPI
|
||||
>);
|
||||
|
||||
hostStorage[data.uri] = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ const redundancyCache = Object.create(null) as Record<
|
||||
function getRedundancyCache(
|
||||
provider: string
|
||||
): IconifyAPIInternalStorage | undefined {
|
||||
if (redundancyCache[provider] === void 0) {
|
||||
if (!redundancyCache[provider]) {
|
||||
const config = getAPIConfig(provider);
|
||||
if (!config) {
|
||||
// Configuration is not set!
|
||||
|
@ -41,7 +41,7 @@ export class Storage {
|
||||
if (!this.canRead) {
|
||||
throw new Error('Restricted storage');
|
||||
}
|
||||
return this.items[name] === void 0 ? null : this.items[name];
|
||||
return name in this.items ? this.items[name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,21 +56,19 @@ export function sortIcons(icons: IconifyIconName[]): SortedIcons {
|
||||
const prefix = icon.prefix;
|
||||
const name = icon.name;
|
||||
|
||||
if (storage[provider] === void 0) {
|
||||
storage[provider] = Object.create(null) as Record<
|
||||
const providerStorage =
|
||||
storage[provider] ||
|
||||
(storage[provider] = Object.create(null) as Record<
|
||||
string,
|
||||
IconStorage
|
||||
>;
|
||||
}
|
||||
const providerStorage = storage[provider];
|
||||
>);
|
||||
|
||||
if (providerStorage[prefix] === void 0) {
|
||||
providerStorage[prefix] = getStorage(provider, prefix);
|
||||
}
|
||||
const localStorage = providerStorage[prefix];
|
||||
const localStorage =
|
||||
providerStorage[prefix] ||
|
||||
(providerStorage[prefix] = getStorage(provider, prefix));
|
||||
|
||||
let list;
|
||||
if (localStorage.icons[name] !== void 0) {
|
||||
if (name in localStorage.icons) {
|
||||
list = result.loaded;
|
||||
} else if (prefix === '' || localStorage.missing.has(name)) {
|
||||
// Mark icons without prefix as missing because they cannot be loaded from API
|
||||
|
Loading…
Reference in New Issue
Block a user