Skip to content

Commit

Permalink
Revert "fix issue with reading asyc store (#49)" (#52)
Browse files Browse the repository at this point in the history
This reverts commit 3edf040.
  • Loading branch information
bluebill1049 authored Jul 29, 2020
1 parent d586e15 commit 451bc43
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/logic/getBrowserStoreData.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/logic/getSyncStoreData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/logic/storeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
export default function storeFactory<T>(
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;

Expand Down
28 changes: 14 additions & 14 deletions src/stateMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ export function createStore<T extends Store = Store>(
},
) {
const storeName = options ? options.name : STORE_DEFAULT_NAME;
storeFactory<T>(storageType, storeName).then(methods => {
if (isDevMode && isClient) {
// @ts-ignore
window['STATE_MACHINE_NAME'] = storeName;
}
const methods = storeFactory<T>(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<T>(props: T) {
Expand Down

0 comments on commit 451bc43

Please sign in to comment.