Extra entries on the undo stack

I spent some of this afternoon looking at a problem reported on the VSX forum.  The questioner has customized the designer and is getting multiple entries on the undo stack as a consequence of a single change.  I coded up his example, but in my case I only got a single entry on the undo stack.  What could the difference be?

The answer may be that there are custom event handlers which listen to store changes and create new transactions.  In the IMS, events are fired when a transaction commits, and are intended for synchronizing state outside of the store, most likely a user interface.  You should not create new transactions in an event handler, because if you do you will indeed get multiple entries on the undo stack.  If you want to synchronize one part of the store with another, you should use Rules: these cause changes to be propagated across the store within a single transaction.  Rules do not need to run on undo or redo, because the complete state of the store, including changes propagated via rules, is undone/redone in one go.


Skip to main content