chore: add options for init function, expose loading state

This commit is contained in:
Vjacheslav Trushkin 2024-01-17 14:29:31 +02:00
parent ceb3fc4394
commit 2963c7a666
3 changed files with 29 additions and 6 deletions

View File

@ -3,7 +3,7 @@
"description": "Iconify API",
"author": "Vjacheslav Trushkin",
"license": "MIT",
"version": "3.1.0-beta.1",
"version": "3.1.0-beta.2",
"publishConfig": {
"access": "public",
"tag": "next"

View File

@ -22,6 +22,13 @@ export function loaded() {
}
}
/**
* Get state
*/
export function isLoading() {
return loading;
}
/**
* Run when app is ready
*/

View File

@ -2,19 +2,35 @@ import { getImporters } from './config/icon-sets.js';
import { iconSetsStorage } from './data/icon-set/store/storage.js';
import { setImporters, updateIconSets } from './data/icon-sets.js';
import { cleanupStorageCache } from './data/storage/startup.js';
import { Importer } from './types/importers.js';
interface InitOptions {
// Cleanup storage cache
cleanup?: boolean;
// Importers
importers?: Importer[];
}
/**
* Init API
*/
export async function initAPI() {
export async function initAPI(options: InitOptions = {}) {
// Reset old cache
if (options.cleanup !== false) {
await cleanupStorageCache(iconSetsStorage);
}
// Get all importers and load data
const importers = await getImporters();
let importers = options.importers;
if (!importers) {
importers = await getImporters();
for (let i = 0; i < importers.length; i++) {
await importers[i].init();
}
}
// Update
setImporters(importers);
updateIconSets();
}