Closed vincentfretin closed 1 month ago
from a product perspective, there are a couple things to consider...
Some thoughts to the above:
More questions:
Looking deeper in the code...A really naive and simple approach is whenever historychanged
is emitted, we can do something similar as the cloudSaveHandler
and put that on a debounce. This would get us a decent solution. it runs the risk of if the user closes the tab prior to the save / during function firing.
CRDTs and doing multiplayer will require a pretty major rewrite. I dont think it's necessary to pursue this at the moment.
From a phasing perspective, we could do the following:
Oh yes I forgot we had the historychanged
event, good call.
Saving the serialized json in localStorage should be enough for now, the maximum size limit for localStorage is about 5 MB per origin in all browsers.
Multi-users edit is indeed a bit more complex to implement. There are indeed some CRDT libraries like https://github.com/yjs/yjs that we could use for this, you would also need a server with WebSocket. To avoid conflicts we should also save at the entity level, each entity required to have an id. IndexedDB and a syncing engine would be good to have offline data, I used kinto a few years ago on a project to edit collaboratively a scene each user on different parts of the scene, and when I saved, it synced again both way, and I got the changes from the other user.
Autosave changes a few seconds later after the user made changes. With #704 done, all the user changes are now undoable. To know if there is any change to save, we can listen to the events entitycreate, entityclone, entityremoved, entityupdate, componentadd, componentremove.