JackAdams / meteor-transactions

App level transactions for Meteor + Mongo
http://transactions.taonova.com/
MIT License
113 stars 16 forks source link

undo/redo for unmanaged (unsynchronized) local collections #8

Closed christianvoigt closed 9 years ago

christianvoigt commented 9 years ago

Hi, I would like to use meteor-transactions for adding an undo/redo stack to a text-editor. The local changes in the editor are not constantly synched with a server-side collection but only with a local collection. Is it possible to use the tx with local collections (new Mongo.Collection(null))? I think this might be a common use case and it would be nice if meteor-transactions supported it. So far I have run into some errors, probably because tx can not find the collection on the server.

JackAdams commented 9 years ago

Hmm... I see your point. That would be quite a departure from the current functionality, which persists all changes (and records of changes) to mongo, but I've been thinking about this sort of thing over the last few days while planning a rewrite to allow for proper mongo 2-phase commits (as per the mongo docs). The rewrite I have in mind would certainly make what you're suggesting an easier proposition.

With regards to the text editor, if the local changes don't need to be persisted to the server, what about the native execCommand('undo); and execCommand('redo); on contenteditable elements? The code in this file might be useful. (Search for hotKeys.)

Another thing that might be worth looking into is https://github.com/mizzao/meteor-sharejs. This gives operational transform to the ace editor, which is pretty cool for collaborative editing. Not sure how easy undo/redo is with that though.

christianvoigt commented 9 years ago

thanks for the links! I didn't know Sharejs, it's really cool. I would love to try that out. Right now I am not working on collaborative editing, though.

I can't use execCommand(), because I am not using the default editing features of contenteditable (because I think the browser differences are a nightmare). All changes are made directly to the models (similar to the editor at medium.com), so there is only a one-way binding.

I am really looking forward to your rewrite!