0
votes

In RxPy, is there anything similar to INotifyPropertyChanged in .NET framework mentioned here? I'm trying to add an observer to an object, so that any property of the object changes, a function will be called.

1

1 Answers

1
votes

Try something like this:

class A(object):
    def __init__(self):
        self._my_attr = None
        self.property_changed = Subject()
    ...
    @property
    def my_attr(self):
        return self._my_attr

    @my_attr.setter
    def my_attr(self, value):
        if value != self._my_attr:
            self._my_attr = value
            self.property_changed.on_next(('my_attr', value))

a = A()
a.property_changed.subscribe(print)
a.my_attr = 1
a.my_attr = 3