Property-like FrameworkΒΆ

In Python, simple operations can be implemented as a property. UndoManager has a property decorator method for this purpose.

from collections_undo import UndoManager

class A:
    mgr = UndoManager()

    def __init__(self):
        self._x = 0

    @mgr.property
    def x(self) -> int:
        return self._x

    @x.setter
    def x(self, val: int):
        self._x = val

x is now a undoable property.

>>> a = A()
>>> a.x = 10
>>> a.x
10
>>> a.mgr.undo()
>>> a.x
0
>>> a.mgr.redo()
>>> a.x
10

Note

You can consider this as a special case of Server-receiver Framework.