Reactions (objetto.reactions)
Reactions.
- @objetto.reactions.reaction(func=None, priority=None)
Decorates an object’s method into a custom reaction. Reaction methods are called automatically when an action propagates up the hierarchy during the ‘PRE’ and ‘POST’ phases.
. code:: python
>>> from objetto.applications import Application >>> from objetto.objects import Object, attribute >>> from objetto.reactions import reaction
>>> class MyObject(Object): ... value = attribute(int, default=0) ... ... @reaction ... def __on_received(self, action, phase): ... if not self._initializing: ... print(("LAST -", action.change.name, phase)) ... ... @reaction(priority=1) ... def __on_received_first(self, action, phase): ... if not self._initializing: ... print(("FIRST -", action.change.name, phase)) ... >>> app = Application() >>> my_obj = MyObject(app) >>> my_obj.value = 42 ('FIRST -', 'Update Attributes', <Phase.PRE: 'PRE'>) ('LAST -', 'Update Attributes', <Phase.PRE: 'PRE'>) ('FIRST -', 'Update Attributes', <Phase.POST: 'POST'>) ('LAST -', 'Update Attributes', <Phase.POST: 'POST'>)
- Parameters
func (function) – Method to be decorated or None.
priority (int or None) – Priority.
- Returns
Decorated custom reaction method or decorator.
- Return type
- class objetto.reactions.CustomReaction(func, priority=None)
Custom method-like that gets called whenever an action is sent through the object.
- Inherits from:
- Parameters
func (function) – Function.
priority (int or None) – Priority.
- __call__(obj, action, phase)
Run function.
- Parameters
obj (objetto.bases.BaseObject) – Object.
action (objetto.objects.Action) – Action.
phase (objetto.constants.PRE or
objetto.constants.POST) – Phase.
- property func
Function.
- Return type
function
- class objetto.reactions.UniqueAttributes(*names, **incrementers)
Asserts that children have unique attributes within a collection. Initialize with attribute names and optional incrementer functions.
- Inherits from:
- Parameters
names (str) – Attribute names.
incrementers (function) – Incrementer functions.
- __call__(obj, action, phase)
React to new children or children’s attribute changes.
- Parameters
obj (objetto.bases.BaseObject) – Object.
action (objetto.objects.Action) – Action.
phase (objetto.constants.PRE or
objetto.constants.POST) – Phase.
- property incrementers
Incrementer functions.
- Return type
objetto.states.DictState[str, function]
- class objetto.reactions.LimitChildren(minimum=None, maximum=None)
Limit the number of children.
- Inherits from:
- __call__(obj, action, phase)
React to atomic changes.
- Parameters
obj (objetto.bases.BaseObject) – Object.
action (objetto.objects.Action) – Action.
phase (objetto.constants.PRE or
objetto.constants.POST) – Phase.