henck / trizbort

This is a browser implementation of the Trizbort adventure game mapping and code generation software.
MIT License
25 stars 16 forks source link

Save state continuously; don't wait for unload #73

Open dfabulich opened 4 years ago

dfabulich commented 4 years ago

Apropos this comment:

I've removed the beforeunload event. Instead, on unload, the current map gets saved to localStorage.

I think it would be better to save state as the user creates it (every time something is pushed onto the "undo" stack). That way, state will survive even if the browser tab crashes.

(If we do this, I think it would make sense to switch to IndexedDB, which has an async API, to ensure that saving the map doesn't lock the main thread. I recommend idb-keyval.)