Open davidbrochart opened 1 year ago
This is dangerous for few reasons:
UndoManager
is not bound to a transaction and has separate way of tracking changes. Also since undo
/redo
are compensating actions, they don't suffer from issues produced by pt2.I mainly agree with 3. When we want to rollback because of an external update, the arrival time of the update is very unpredictable anyway, because it may be sent over a network or some kind of IO. So the update may arrive after the transaction, in which case it's too late to rollback.
I know that Yrs doesn't support rollback, but allows undoing changes. Still, I'm wondering if it would make sense to be able to cancel a transaction. One use case I'm thinking about is when a change to a document occurs while in a transaction. In this case we might want to react to that change and not commit the current changes, to do something different. To implement this, I think we could add a wrapper around the current types, that would not call Yrs right away but instead register the changes to actually be done when the transaction context manager exits. These "views" should reflect the changes right away though, so that we can read their content. For instance:
But since this code is blocking, a document change cannot be seen in the middle of a transaction. So this would really be useful if the API is async, as mentioned here (but for a different reason).