homotopy-io / homotopy-webclient

https://homotopy.io
27 stars 5 forks source link

Compression of workspaces #48

Closed jamievicary closed 5 years ago

jamievicary commented 5 years ago

Exported workspaces will be very large, easily running into tens of megabytes. We want to be pushing these around a lot --- letting the user download them, putting them on to the history stack for undo/redo, sending them to the server, etc. So I think we need an in-browser way to compress them.

jamievicary commented 5 years ago

This looks like a good option: https://github.com/rt2zz/redux-persist-transform-compress

jamievicary commented 5 years ago

Now working for persisted state in localStorage.

jamievicary commented 5 years ago

Does anyone know how to hook this into the undo/redo browser buttons?

joliss commented 5 years ago

Does anyone know how to hook this into the undo/redo browser buttons?

I think you would hook into the onpopstate event. You can bind to it with jQuery like so: $(window).on('popstate', function(e) { ... e.originalEvent.state ... })

To stop it from firing when you programmatically change the hash, instead of assigning window.location.hash you'd want to do use pushState, e.g. window.history.pushState({}, "", "#foo"). The first argument ({}) is a state object that you get back in the popstate event handler. You can pass anything here; the idea is that it lets the popstate handler avoid having to deserialize the hash by storing the application's history state directly.

jamievicary commented 5 years ago

This sounds good, although it would be good to avoid jQuery, it feels a bit weird mixing that with React.

Lukas is currently fixing some issues with state persistence. Once that is done it will be easier to implement this URL idea.

jamievicary commented 5 years ago

Done and working on master.