Skip to content

Commit

Permalink
fix #16 using node
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Dec 30, 2019
1 parent cbbe592 commit 1c74218
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/stateMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import {
import { useCallback } from 'react';

let action: ActionName;
let storageType: Storage =
typeof window === 'undefined'
? {
getItem: payload => payload,
setItem: (payload: string) => payload,
clear: () => {},
length: 0,
key: (payload: number) => payload.toString(),
removeItem: () => {},
}
: window.sessionStorage;
const isClient = typeof window !== 'undefined';
let storageType: Storage = isClient
? window.sessionStorage
: {
getItem: payload => payload,
setItem: (payload: string) => payload,
clear: () => {},
length: 0,
key: (payload: number) => payload.toString(),
removeItem: () => {},
};
let getStore: GetStore;
let setStore: SetStore;
let getName: GetStoreName;
Expand All @@ -59,7 +59,7 @@ export function createStore<T extends Store = Store>(
const storeName = options ? options.name : STORE_DEFAULT_NAME;
const methods = storeFactory<T>(storageType, storeName);

if (isDevMode) {
if (isDevMode && isClient) {
// @ts-ignore
window['STATE_MACHINE_NAME'] = storeName;
}
Expand Down

0 comments on commit 1c74218

Please sign in to comment.