From 0f3457b6ee0a8dada19fc1d8c08c707dd8378554 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 12 Aug 2020 21:21:20 +0300 Subject: [PATCH] Add disableStorage function to SVG framework --- packages/iconify/src/iconify.ts | 35 +++++++++++++++++------------ packages/iconify/src/modules/api.ts | 3 ++- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/packages/iconify/src/iconify.ts b/packages/iconify/src/iconify.ts index 6bd8b83..5c1c459 100644 --- a/packages/iconify/src/iconify.ts +++ b/packages/iconify/src/iconify.ts @@ -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 diff --git a/packages/iconify/src/modules/api.ts b/packages/iconify/src/modules/api.ts index f8ffbfb..ec3d2b6 100644 --- a/packages/iconify/src/modules/api.ts +++ b/packages/iconify/src/modules/api.ts @@ -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