From 41950aaf466a00cdac09e12f2eb5b81347630a56 Mon Sep 17 00:00:00 2001 From: Rasul Date: Sat, 21 Sep 2024 16:11:12 +0200 Subject: [PATCH] refactor: theme storage improve usability (#743) --- packages/storage/lib/{ => base}/base.ts | 0 packages/storage/lib/{ => base}/enums.ts | 0 packages/storage/lib/{ => base}/types.ts | 6 ------ .../storage/lib/{ => impl}/exampleThemeStorage.ts | 12 +++++++++--- packages/storage/lib/impl/index.ts | 1 + packages/storage/lib/index.ts | 9 ++------- 6 files changed, 12 insertions(+), 16 deletions(-) rename packages/storage/lib/{ => base}/base.ts (100%) rename packages/storage/lib/{ => base}/enums.ts (100%) rename packages/storage/lib/{ => base}/types.ts (91%) rename packages/storage/lib/{ => impl}/exampleThemeStorage.ts (59%) create mode 100644 packages/storage/lib/impl/index.ts diff --git a/packages/storage/lib/base.ts b/packages/storage/lib/base/base.ts similarity index 100% rename from packages/storage/lib/base.ts rename to packages/storage/lib/base/base.ts diff --git a/packages/storage/lib/enums.ts b/packages/storage/lib/base/enums.ts similarity index 100% rename from packages/storage/lib/enums.ts rename to packages/storage/lib/base/enums.ts diff --git a/packages/storage/lib/types.ts b/packages/storage/lib/base/types.ts similarity index 91% rename from packages/storage/lib/types.ts rename to packages/storage/lib/base/types.ts index fd123b78b..52fd09f69 100644 --- a/packages/storage/lib/types.ts +++ b/packages/storage/lib/base/types.ts @@ -9,12 +9,6 @@ export type BaseStorage = { subscribe: (listener: () => void) => () => void; }; -export type Theme = 'light' | 'dark'; - -export type ThemeStorage = BaseStorage & { - toggle: () => Promise; -}; - export type StorageConfig = { /** * Assign the {@link StorageEnum} to use. diff --git a/packages/storage/lib/exampleThemeStorage.ts b/packages/storage/lib/impl/exampleThemeStorage.ts similarity index 59% rename from packages/storage/lib/exampleThemeStorage.ts rename to packages/storage/lib/impl/exampleThemeStorage.ts index f940c8d87..9573c27b5 100644 --- a/packages/storage/lib/exampleThemeStorage.ts +++ b/packages/storage/lib/impl/exampleThemeStorage.ts @@ -1,6 +1,12 @@ -import { createStorage } from './base'; -import { StorageEnum } from './enums'; -import type { Theme, ThemeStorage } from './types'; +import { StorageEnum } from '../base/enums'; +import { createStorage } from '../base/base'; +import type { BaseStorage } from '../base/types'; + +type Theme = 'light' | 'dark'; + +type ThemeStorage = BaseStorage & { + toggle: () => Promise; +}; const storage = createStorage('theme-storage-key', 'light', { storageEnum: StorageEnum.Local, diff --git a/packages/storage/lib/impl/index.ts b/packages/storage/lib/impl/index.ts new file mode 100644 index 000000000..bb9f0cbc4 --- /dev/null +++ b/packages/storage/lib/impl/index.ts @@ -0,0 +1 @@ +export * from './exampleThemeStorage'; diff --git a/packages/storage/lib/index.ts b/packages/storage/lib/index.ts index f051453d9..3172289bb 100644 --- a/packages/storage/lib/index.ts +++ b/packages/storage/lib/index.ts @@ -1,7 +1,2 @@ -import { createStorage } from './base'; -import { exampleThemeStorage } from './exampleThemeStorage'; -import { SessionAccessLevelEnum, StorageEnum } from './enums'; -import type { BaseStorage } from './types'; - -export { exampleThemeStorage, createStorage, StorageEnum, SessionAccessLevelEnum }; -export type { BaseStorage }; +export type { BaseStorage } from './base/types'; +export * from './impl';