How does undo
work? Does it copy all the managed objects every time any of the values change? Or does it only copy the actual changes together with an information which objects were affected? Is that heavy or lightweight?
相关问题
- how to define constructor for Python's new Nam
- Keeping track of variable instances
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Object.create() bug?
相关文章
- 现在使用swift开发ios应用好还是swift?
- 接口B继承接口A,但是又不添加新的方法。这样有什么意义吗?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Should client-server code be written in one “proje
Here's a rough implementation to get you thinking. This handles your stack of undoable operations. (It doesn't handle redo, but that's easy to support by replacing the stack with a list and keeping track of the current item.)
To use this, let's say the user can change a value in some object like this:
To make that operation undoable, we just change the setter to:
Now, if you call Undoable.Undo() from anywhere in the application, your instance of Foo will restore the previous value of Bar. If Foo also raises an event when Bar changes (not shown here), the UI will also properly refresh on undo too.
The 'undo' mechanism for pretty much any language that supports Object-Oriented constructs uses the Memento Design Pattern to make it happen.