mirror of https://github.com/iconify/api.git
chore: add options for init function, expose loading state
This commit is contained in:
parent
ceb3fc4394
commit
2963c7a666
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ export function loaded() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get state
|
||||
*/
|
||||
export function isLoading() {
|
||||
return loading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run when app is ready
|
||||
*/
|
||||
|
|
|
|||
20
src/init.ts
20
src/init.ts
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue