

let lastSave = new Date();

export function clearData() {
    lastSave = new Date();
    if (window.confirm("Wipe app data and reload page?")) {
        window.localStorage.setItem("appState", undefined);
        location.reload();
    }
}

export function persistenceMiddleware({getState}) {
    return (next) => (action) => {

        const nextState = next(action);

        let now = new Date();
        if (now.getTime() - lastSave.getTime() < 10000) {
            return nextState;
        }

        saveToLocalStorage(getState());
        console.log('Saved state ...');
        lastSave = new Date();
        return nextState;
    }
}

export function saveToLocalStorage(state) {
    const {form, modalDialog ,...savableState} = state;
    window.localStorage.setItem("appState", JSON.stringify(savableState));
}


export function loadFromLocalStorage() {
    const stateString = window.localStorage.getItem("appState");
    let state = undefined;
    try {
        state = JSON.parse(stateString);
    }
    catch (e) {
        console.error("Failed to load state from local storage. Data: " + stateString);
    }
    console.log("Loaded state:");
    console.log(state);
    return state !== null ? state : undefined;
}
@@ -1,10 +1,8 @@
-%0A%0A
 let last
@@ -678,24 +678,167 @@
 ge(state) %7B%0A
+    if (typeof window === 'undefined') %7B%0A        console.warn(%22Can not save to local storage in current environment.%22);%0A        return;%0A    %7D%0A%0A
     const %7Bf
@@ -997,24 +997,179 @@
 Storage() %7B%0A
+    if (typeof window === 'undefined') %7B%0A        console.warn(%22Can not load from local storage in current environment.%22);%0A        return undefined;%0A    %7D%0A%0A
     const st

Fix Tests