2
0
mirror of https://github.com/iconify/iconify.git synced 2024-09-19 16:59:02 +00:00

Add disableStorage function to SVG framework

This commit is contained in:
Vjacheslav Trushkin 2020-08-12 21:21:20 +03:00
parent 2a1b3a2b8b
commit 0f3457b6ee
2 changed files with 23 additions and 15 deletions

View File

@ -112,6 +112,21 @@ export interface IconifyGlobal extends IconifyGlobal1, IconifyGlobal2 {}
// Export dependencies
export { IconifyGlobal as IconifyGlobalCommon, IconifyAPI };
function toggleCache(storage: IconifyCacheType, value: boolean): void {
switch (storage) {
case 'local':
case 'session':
config[storage] = value;
break;
case 'all':
for (const key in config) {
config[key] = value;
}
break;
}
}
/**
* Global variable
*/
@ -122,20 +137,12 @@ const Iconify: IconifyGlobal = ({
// API providers
addAPIProvider: setAPIConfig,
// Allow storage
enableCache: (storage: IconifyCacheType, value: boolean) => {
switch (storage) {
case 'local':
case 'session':
config[storage] = value;
break;
case 'all':
for (const key in config) {
config[key] = value;
}
break;
}
// Toggle storage
enableCache: (storage: IconifyCacheType, value?: boolean) => {
toggleCache(storage, typeof value === 'boolean' ? value : true);
},
disableCache: (storage: IconifyCacheType) => {
toggleCache(storage, false);
},
// Exposed internal functions

View File

@ -20,7 +20,8 @@ export interface IconifyAPI {
/**
* Toggle local and session storage
*/
enableCache: (storage: IconifyCacheType, value: boolean) => void;
enableCache: (storage: IconifyCacheType, value?: boolean) => void;
disableCache: (storage: IconifyCacheType) => void;
/**
* Load icons