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;
|
const name = icon.name;
|
||||||
if (storage.icons[name] !== void 0) {
|
if (storage.icons[name]) {
|
||||||
// Loaded
|
// Loaded
|
||||||
icons.loaded.push({
|
icons.loaded.push({
|
||||||
provider,
|
provider,
|
||||||
|
@ -109,35 +109,45 @@ export function mockAPIData(data: IconifyMockAPI): void {
|
|||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case 'icons': {
|
case 'icons': {
|
||||||
const provider = data.provider;
|
const provider = data.provider;
|
||||||
if (iconsStorage[provider] === void 0) {
|
|
||||||
iconsStorage[provider] = {};
|
|
||||||
}
|
|
||||||
const providerStorage = iconsStorage[provider];
|
|
||||||
|
|
||||||
const prefix = data.prefix;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'custom': {
|
case 'custom': {
|
||||||
const provider = data.provider;
|
const provider = data.provider;
|
||||||
if (customProviderStorage[provider] === void 0) {
|
|
||||||
customProviderStorage[provider] = {};
|
const providerStorage =
|
||||||
}
|
customProviderStorage[provider] ||
|
||||||
customProviderStorage[provider][data.uri] = data;
|
(customProviderStorage[provider] = Object.create(
|
||||||
|
null
|
||||||
|
) as Record<string, IconifyMockCustomAPI>);
|
||||||
|
|
||||||
|
providerStorage[data.uri] = data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'host': {
|
case 'host': {
|
||||||
const host = data.host;
|
const host = data.host;
|
||||||
if (customHostStorage[host] === void 0) {
|
|
||||||
customHostStorage[host] = {};
|
const hostStorage =
|
||||||
}
|
customHostStorage[host] ||
|
||||||
customHostStorage[host][data.uri] = data;
|
(customHostStorage[host] = Object.create(null) as Record<
|
||||||
|
string,
|
||||||
|
IconifyMockCustomHostAPI
|
||||||
|
>);
|
||||||
|
|
||||||
|
hostStorage[data.uri] = data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ const redundancyCache = Object.create(null) as Record<
|
|||||||
function getRedundancyCache(
|
function getRedundancyCache(
|
||||||
provider: string
|
provider: string
|
||||||
): IconifyAPIInternalStorage | undefined {
|
): IconifyAPIInternalStorage | undefined {
|
||||||
if (redundancyCache[provider] === void 0) {
|
if (!redundancyCache[provider]) {
|
||||||
const config = getAPIConfig(provider);
|
const config = getAPIConfig(provider);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
// Configuration is not set!
|
// Configuration is not set!
|
||||||
|
@ -41,7 +41,7 @@ export class Storage {
|
|||||||
if (!this.canRead) {
|
if (!this.canRead) {
|
||||||
throw new Error('Restricted storage');
|
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 prefix = icon.prefix;
|
||||||
const name = icon.name;
|
const name = icon.name;
|
||||||
|
|
||||||
if (storage[provider] === void 0) {
|
const providerStorage =
|
||||||
storage[provider] = Object.create(null) as Record<
|
storage[provider] ||
|
||||||
|
(storage[provider] = Object.create(null) as Record<
|
||||||
string,
|
string,
|
||||||
IconStorage
|
IconStorage
|
||||||
>;
|
>);
|
||||||
}
|
|
||||||
const providerStorage = storage[provider];
|
|
||||||
|
|
||||||
if (providerStorage[prefix] === void 0) {
|
const localStorage =
|
||||||
providerStorage[prefix] = getStorage(provider, prefix);
|
providerStorage[prefix] ||
|
||||||
}
|
(providerStorage[prefix] = getStorage(provider, prefix));
|
||||||
const localStorage = providerStorage[prefix];
|
|
||||||
|
|
||||||
let list;
|
let list;
|
||||||
if (localStorage.icons[name] !== void 0) {
|
if (name in localStorage.icons) {
|
||||||
list = result.loaded;
|
list = result.loaded;
|
||||||
} else if (prefix === '' || localStorage.missing.has(name)) {
|
} 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
|
||||||
|
Loading…
Reference in New Issue
Block a user