From a64b9a78ff4eb61b283f96b8543dffa6966f35b9 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 21 May 2022 22:55:01 +0300 Subject: [PATCH] Remove shareStorage function - no longer needed because web component reuses same class even if bundled multiple times --- components/ember/src/iconify-icon.ts | 4 +- components/react/src/iconify.ts | 4 +- components/svelte/src/Icon.svelte | 2 - components/svelte/src/functions.ts | 4 +- components/svelte/src/iconify.ts | 1 - components/svg-framework/src/iconify.ts | 5 +-- .../svg-framework/src/iconify.without-api.ts | 5 +-- components/vue/src/iconify.ts | 4 +- components/vue2/src/iconify.ts | 4 +- iconify-icon/icon/src/functions.ts | 3 +- iconify-icon/icon/src/index.ts | 2 - iconify-icon/react/src/iconify.ts | 1 - iconify-icon/solid/src/iconify.tsx | 1 - packages/core/src/storage/functions.ts | 9 ---- packages/core/src/storage/storage.ts | 43 +------------------ 15 files changed, 16 insertions(+), 76 deletions(-) diff --git a/components/ember/src/iconify-icon.ts b/components/ember/src/iconify-icon.ts index 490a565..c1f77de 100644 --- a/components/ember/src/iconify-icon.ts +++ b/components/ember/src/iconify-icon.ts @@ -11,7 +11,7 @@ import { addCollection, allowSimpleNames, } from '@iconify/core/lib/storage/functions'; -import { listIcons, shareStorage } from '@iconify/core/lib/storage/storage'; +import { listIcons } from '@iconify/core/lib/storage/storage'; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions'; import { buildIcon } from '@iconify/core/lib/builder/functions'; import { replaceIDs } from '@iconify/utils/lib/svg/id'; @@ -228,7 +228,7 @@ export { _api }; export { addAPIProvider, loadIcons, loadIcon }; // IconifyStorageFunctions -export { iconExists, getIcon, listIcons, addIcon, addCollection, shareStorage }; +export { iconExists, getIcon, listIcons, addIcon, addCollection }; // IconifyBuilderFunctions export { replaceIDs, calculateSize, buildIcon }; diff --git a/components/react/src/iconify.ts b/components/react/src/iconify.ts index f6f2d9d..bc3956e 100644 --- a/components/react/src/iconify.ts +++ b/components/react/src/iconify.ts @@ -14,7 +14,7 @@ import { getIconData, allowSimpleNames, } from '@iconify/core/lib/storage/functions'; -import { listIcons, shareStorage } from '@iconify/core/lib/storage/storage'; +import { listIcons } from '@iconify/core/lib/storage/storage'; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions'; import { buildIcon } from '@iconify/core/lib/builder/functions'; import { replaceIDs } from '@iconify/utils/lib/svg/id'; @@ -464,7 +464,7 @@ export { _api }; export { addAPIProvider, loadIcons, loadIcon }; // IconifyStorageFunctions -export { iconExists, getIcon, listIcons, addIcon, addCollection, shareStorage }; +export { iconExists, getIcon, listIcons, addIcon, addCollection }; // IconifyBuilderFunctions export { replaceIDs, calculateSize, buildIcon }; diff --git a/components/svelte/src/Icon.svelte b/components/svelte/src/Icon.svelte index 15af2c9..bc611fc 100644 --- a/components/svelte/src/Icon.svelte +++ b/components/svelte/src/Icon.svelte @@ -8,7 +8,6 @@ import { iconExists, getIcon, listIcons, - shareStorage, addIcon, addCollection, calculateSize, @@ -26,7 +25,6 @@ export { iconExists, getIcon, listIcons, - shareStorage, addIcon, addCollection, calculateSize, diff --git a/components/svelte/src/functions.ts b/components/svelte/src/functions.ts index 879dc3f..73dd28a 100644 --- a/components/svelte/src/functions.ts +++ b/components/svelte/src/functions.ts @@ -13,7 +13,7 @@ import { getIconData, allowSimpleNames, } from '@iconify/core/lib/storage/functions'; -import { listIcons, shareStorage } from '@iconify/core/lib/storage/storage'; +import { listIcons } from '@iconify/core/lib/storage/storage'; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions'; import { buildIcon } from '@iconify/core/lib/builder/functions'; import { replaceIDs } from '@iconify/utils/lib/svg/id'; @@ -358,7 +358,7 @@ export { _api }; export { addAPIProvider, loadIcons, loadIcon }; // IconifyStorageFunctions -export { iconExists, getIcon, listIcons, addIcon, addCollection, shareStorage }; +export { iconExists, getIcon, listIcons, addIcon, addCollection }; // IconifyBuilderFunctions export { replaceIDs, calculateSize, buildIcon }; diff --git a/components/svelte/src/iconify.ts b/components/svelte/src/iconify.ts index a64b12b..a43bfd5 100644 --- a/components/svelte/src/iconify.ts +++ b/components/svelte/src/iconify.ts @@ -55,7 +55,6 @@ export { listIcons, addIcon, addCollection, - shareStorage, } from './functions'; export { calculateSize, replaceIDs, buildIcon } from './functions'; diff --git a/components/svg-framework/src/iconify.ts b/components/svg-framework/src/iconify.ts index 28d91ce..0555aec 100644 --- a/components/svg-framework/src/iconify.ts +++ b/components/svg-framework/src/iconify.ts @@ -13,7 +13,7 @@ import { addIcon, addCollection, } from '@iconify/core/lib/storage/functions'; -import { listIcons, shareStorage } from '@iconify/core/lib/storage/storage'; +import { listIcons } from '@iconify/core/lib/storage/storage'; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions'; import { buildIcon } from '@iconify/core/lib/builder/functions'; import { replaceIDs } from '@iconify/utils/lib/svg/id'; @@ -213,7 +213,6 @@ const Iconify: IconifyGlobal = { listIcons, addIcon, addCollection, - shareStorage, // IconifyBuilderFunctions replaceIDs, @@ -251,7 +250,7 @@ export { _api }; export { addAPIProvider, loadIcons, loadIcon }; // IconifyStorageFunctions -export { iconExists, getIcon, listIcons, addIcon, addCollection, shareStorage }; +export { iconExists, getIcon, listIcons, addIcon, addCollection }; // IconifyBuilderFunctions export { replaceIDs, calculateSize, buildIcon }; diff --git a/components/svg-framework/src/iconify.without-api.ts b/components/svg-framework/src/iconify.without-api.ts index 93aa4e6..69e7d9f 100644 --- a/components/svg-framework/src/iconify.without-api.ts +++ b/components/svg-framework/src/iconify.without-api.ts @@ -13,7 +13,7 @@ import { addIcon, addCollection, } from '@iconify/core/lib/storage/functions'; -import { listIcons, shareStorage } from '@iconify/core/lib/storage/storage'; +import { listIcons } from '@iconify/core/lib/storage/storage'; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions'; import { buildIcon } from '@iconify/core/lib/builder/functions'; import { replaceIDs } from '@iconify/utils/lib/svg/id'; @@ -63,7 +63,6 @@ const Iconify: IconifyGlobal = { listIcons, addIcon, addCollection, - shareStorage, // IconifyBuilderFunctions replaceIDs, @@ -91,7 +90,7 @@ export default Iconify; * Named exports */ // IconifyStorageFunctions -export { iconExists, getIcon, listIcons, addIcon, addCollection, shareStorage }; +export { iconExists, getIcon, listIcons, addIcon, addCollection }; // IconifyBuilderFunctions export { replaceIDs, calculateSize, buildIcon }; diff --git a/components/vue/src/iconify.ts b/components/vue/src/iconify.ts index 5d34b75..0d71193 100644 --- a/components/vue/src/iconify.ts +++ b/components/vue/src/iconify.ts @@ -23,7 +23,7 @@ import { getIconData, allowSimpleNames, } from '@iconify/core/lib/storage/functions'; -import { listIcons, shareStorage } from '@iconify/core/lib/storage/storage'; +import { listIcons } from '@iconify/core/lib/storage/storage'; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions'; import { buildIcon } from '@iconify/core/lib/builder/functions'; import { replaceIDs } from '@iconify/utils/lib/svg/id'; @@ -404,7 +404,7 @@ export { _api }; export { addAPIProvider, loadIcons, loadIcon }; // IconifyStorageFunctions -export { iconExists, getIcon, listIcons, addIcon, addCollection, shareStorage }; +export { iconExists, getIcon, listIcons, addIcon, addCollection }; // IconifyBuilderFunctions export { replaceIDs, calculateSize, buildIcon }; diff --git a/components/vue2/src/iconify.ts b/components/vue2/src/iconify.ts index 7162ed5..1c886a3 100644 --- a/components/vue2/src/iconify.ts +++ b/components/vue2/src/iconify.ts @@ -16,7 +16,7 @@ import { getIconData, allowSimpleNames, } from '@iconify/core/lib/storage/functions'; -import { listIcons, shareStorage } from '@iconify/core/lib/storage/storage'; +import { listIcons } from '@iconify/core/lib/storage/storage'; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions'; import { buildIcon } from '@iconify/core/lib/builder/functions'; import { replaceIDs } from '@iconify/utils/lib/svg/id'; @@ -386,7 +386,7 @@ export { _api }; export { addAPIProvider, loadIcons, loadIcon }; // IconifyStorageFunctions -export { iconExists, getIcon, listIcons, addIcon, addCollection, shareStorage }; +export { iconExists, getIcon, listIcons, addIcon, addCollection }; // IconifyBuilderFunctions export { replaceIDs, calculateSize, buildIcon }; diff --git a/iconify-icon/icon/src/functions.ts b/iconify-icon/icon/src/functions.ts index 7e3957d..9da3d11 100644 --- a/iconify-icon/icon/src/functions.ts +++ b/iconify-icon/icon/src/functions.ts @@ -11,7 +11,7 @@ import { addIcon, addCollection, } from '@iconify/core/lib/storage/functions'; -import { listIcons, shareStorage } from '@iconify/core/lib/storage/storage'; +import { listIcons } from '@iconify/core/lib/storage/storage'; import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions'; import { buildIcon } from '@iconify/core/lib/builder/functions'; import { calculateSize } from '@iconify/utils/lib/svg/size'; @@ -159,7 +159,6 @@ export function exportFunctions(): IconifyExportedFunctions { iconExists, getIcon, listIcons, - shareStorage, addIcon, addCollection, calculateSize, diff --git a/iconify-icon/icon/src/index.ts b/iconify-icon/icon/src/index.ts index 57b5ab0..df7bf93 100644 --- a/iconify-icon/icon/src/index.ts +++ b/iconify-icon/icon/src/index.ts @@ -112,7 +112,6 @@ const { iconExists, getIcon, listIcons, - shareStorage, addIcon, addCollection, calculateSize, @@ -129,7 +128,6 @@ export { iconExists, getIcon, listIcons, - shareStorage, addIcon, addCollection, calculateSize, diff --git a/iconify-icon/react/src/iconify.ts b/iconify-icon/react/src/iconify.ts index 97fdbca..0efed5c 100644 --- a/iconify-icon/react/src/iconify.ts +++ b/iconify-icon/react/src/iconify.ts @@ -60,7 +60,6 @@ export { iconExists, getIcon, listIcons, - shareStorage, addIcon, addCollection, calculateSize, diff --git a/iconify-icon/solid/src/iconify.tsx b/iconify-icon/solid/src/iconify.tsx index 667bc8e..e461ad4 100644 --- a/iconify-icon/solid/src/iconify.tsx +++ b/iconify-icon/solid/src/iconify.tsx @@ -61,7 +61,6 @@ export { iconExists, getIcon, listIcons, - shareStorage, addIcon, addCollection, calculateSize, diff --git a/packages/core/src/storage/functions.ts b/packages/core/src/storage/functions.ts index e7471b8..3b6fcc2 100644 --- a/packages/core/src/storage/functions.ts +++ b/packages/core/src/storage/functions.ts @@ -35,15 +35,6 @@ export interface IconifyStorageFunctions { * Add icon set to storage */ addCollection: (data: IconifyJSON, provider?: string) => boolean; - - /** - * Share storage (used to share icon data between various components or multiple instances of component) - * - * It works by moving storage to global variable, new instances of component attempt to detect global - * variable during load. Therefore, function should be called as soon as possible. - * Works only in browser, not usable in SSR. - */ - shareStorage: () => void; } /** diff --git a/packages/core/src/storage/storage.ts b/packages/core/src/storage/storage.ts index dc16934..3a80056 100644 --- a/packages/core/src/storage/storage.ts +++ b/packages/core/src/storage/storage.ts @@ -19,55 +19,14 @@ export interface IconStorage { missing: Record; } -/** - * Storage format version - */ -const storageVersion = 1; - /** * Storage by provider and prefix */ -let storage = Object.create(null) as Record< +const storage = Object.create(null) as Record< string, Record >; -/** - * Share storage - */ -interface WindowWithStorage extends Window { - _iconifyStorage: { - version: number; - storage: Record>; - }; -} - -try { - const w = (window || self) as unknown as WindowWithStorage | undefined; - if (w && w._iconifyStorage.version === storageVersion) { - storage = w._iconifyStorage.storage; - } -} catch (err) { - // -} - -/** - * Share storage between components - */ -export function shareStorage(): void { - try { - const w = (window || self) as unknown as WindowWithStorage | undefined; - if (w && !w._iconifyStorage) { - w._iconifyStorage = { - version: storageVersion, - storage, - }; - } - } catch (err) { - // - } -} - /** * Create new storage */