diff --git a/src/logic/getBrowserStoreData.ts b/src/logic/getBrowserStoreData.ts index 68e4190..cb87b03 100644 --- a/src/logic/getBrowserStoreData.ts +++ b/src/logic/getBrowserStoreData.ts @@ -1,6 +1,6 @@ -export default async (storageType: Storage, storeName: string) => { +export default (storageType: Storage, storeName: string) => { + const sessionStorageData = storageType.getItem(storeName); try { - const sessionStorageData = await storageType.getItem(storeName); return sessionStorageData ? JSON.parse(sessionStorageData) : undefined; } catch { return undefined; diff --git a/src/logic/getSyncStoreData.ts b/src/logic/getSyncStoreData.ts index f70651b..c099969 100644 --- a/src/logic/getSyncStoreData.ts +++ b/src/logic/getSyncStoreData.ts @@ -34,8 +34,8 @@ export default function getSyncStoreData( store, }); } else { - Object.entries(syncStoreOption).forEach(async ([key, values]) => { - const browserStore = await getBrowserStoreData(storageType, key); + Object.entries(syncStoreOption).forEach(([key, values]) => { + const browserStore = getBrowserStoreData(storageType, key); values.forEach((value: string) => { store = { ...store, diff --git a/src/logic/storeFactory.ts b/src/logic/storeFactory.ts index a5c0097..d182fb3 100644 --- a/src/logic/storeFactory.ts +++ b/src/logic/storeFactory.ts @@ -2,16 +2,16 @@ import { STORE_DEFAULT_NAME } from '../constants'; import { GetStoreName, GetStore, SetStore, Store } from '../types'; import getStoreData from './getBrowserStoreData'; -export default async function storeFactory( +export default function storeFactory( storageType: Storage, name: string | undefined, -): Promise<{ +): { set: SetStore; get: GetStore; getName: GetStoreName; -}> { +} { const storeName = name || STORE_DEFAULT_NAME; - let store: Store = await getStoreData(storageType, storeName); + let store: Store = getStoreData(storageType, storeName); const getName = (): string => storeName; diff --git a/src/stateMachine.tsx b/src/stateMachine.tsx index 153966b..daeb903 100644 --- a/src/stateMachine.tsx +++ b/src/stateMachine.tsx @@ -57,23 +57,23 @@ export function createStore( }, ) { const storeName = options ? options.name : STORE_DEFAULT_NAME; - storeFactory(storageType, storeName).then(methods => { - if (isDevMode && isClient) { - // @ts-ignore - window['STATE_MACHINE_NAME'] = storeName; - } + const methods = storeFactory(storageType, storeName); - getName = methods.getName; - getStore = methods.get; - setStore = methods.set; - middleWaresArray = options.middleWares; + if (isDevMode && isClient) { + // @ts-ignore + window['STATE_MACHINE_NAME'] = storeName; + } - setUpDevTools(isDevMode, storageType, getName, getStore); + getName = methods.getName; + getStore = methods.get; + setStore = methods.set; + middleWaresArray = options.middleWares; - setStore( - getSyncStoreData(getStore() || defaultStoreData, options, storageType), - ); - }); + setUpDevTools(isDevMode, storageType, getName, getStore); + + setStore( + getSyncStoreData(getStore() || defaultStoreData, options, storageType), + ); } export function StateMachineProvider(props: T) {