Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/source/basis/observation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,31 @@ dictionary can contains additional information (note that ``'value'`` and
a.s.connect(print_pair)
a.s('a', 1)

Extended observers
------------------

Atom supports observing a member of a nested Atom object up to one level deep
using the format ``"<member>.<attr>"``. This is called an extended observer and
uses a combination of static and dynamic observers.

.. code-block:: python

from atom.api import Atom, Int, Typed, observe
class Point(Atom):
x = Int()
y = Int()

class Item(Atom):
pos = Typed(Point, ())

@observe("pos.x")
def on_change(self, change):
print(change)

item = Item()
item.pos.x = 1 # Invokes on_change with change event for "x"
item.pos = Point(x=2, y=0) # Does NOT invoke on_change. Add a separate "pos" argument to @observe if this is needed.
item.pos.x = 3 # Invokes on_change with change event for "x"

Suppressing notifications
-------------------------
Expand Down
Loading