|
1 | 1 | from typing import TYPE_CHECKING |
2 | | -from typing import Callable |
3 | 2 | from typing import Iterable |
4 | 3 | from typing import List |
5 | 4 |
|
6 | 5 | from .callbacks import CallbackGroup |
7 | 6 | from .transition import Transition |
| 7 | +from .transition_mixin import AddCallbacksMixin |
8 | 8 | from .utils import ensure_iterable |
9 | 9 |
|
10 | 10 | if TYPE_CHECKING: |
11 | 11 | from .events import Event |
12 | 12 | from .state import State |
13 | 13 |
|
14 | 14 |
|
15 | | -class TransitionList: |
| 15 | +class TransitionList(AddCallbacksMixin): |
16 | 16 | """A list-like container of :ref:`transitions` with callback functions.""" |
17 | 17 |
|
18 | 18 | def __init__(self, transitions: "Iterable[Transition] | None" = None): |
@@ -97,80 +97,6 @@ def _add_callback(self, callback, grouper: CallbackGroup, is_event=False, **kwar |
97 | 97 | ) |
98 | 98 | return callback |
99 | 99 |
|
100 | | - def __call__(self, f): |
101 | | - return self._add_callback(f, CallbackGroup.ON, is_event=True) |
102 | | - |
103 | | - def before(self, f: Callable): |
104 | | - """Adds a ``before`` :ref:`transition actions` callback to every :ref:`transition` in the |
105 | | - :ref:`TransitionList` instance. |
106 | | -
|
107 | | - Args: |
108 | | - f: The ``before`` :ref:`transition actions` callback function to be added. |
109 | | -
|
110 | | - Returns: |
111 | | - The `f` callable. |
112 | | - """ |
113 | | - return self._add_callback(f, CallbackGroup.BEFORE) |
114 | | - |
115 | | - def after(self, f: Callable): |
116 | | - """Adds a ``after`` :ref:`transition actions` callback to every :ref:`transition` in the |
117 | | - :ref:`TransitionList` instance. |
118 | | -
|
119 | | - Args: |
120 | | - f: The ``after`` :ref:`transition actions` callback function to be added. |
121 | | -
|
122 | | - Returns: |
123 | | - The `f` callable. |
124 | | - """ |
125 | | - return self._add_callback(f, CallbackGroup.AFTER) |
126 | | - |
127 | | - def on(self, f: Callable): |
128 | | - """Adds a ``on`` :ref:`transition actions` callback to every :ref:`transition` in the |
129 | | - :ref:`TransitionList` instance. |
130 | | -
|
131 | | - Args: |
132 | | - f: The ``on`` :ref:`transition actions` callback function to be added. |
133 | | -
|
134 | | - Returns: |
135 | | - The `f` callable. |
136 | | - """ |
137 | | - return self._add_callback(f, CallbackGroup.ON) |
138 | | - |
139 | | - def cond(self, f: Callable): |
140 | | - """Adds a ``cond`` :ref:`guards` callback to every :ref:`transition` in the |
141 | | - :ref:`TransitionList` instance. |
142 | | -
|
143 | | - Args: |
144 | | - f: The ``cond`` :ref:`guards` callback function to be added. |
145 | | -
|
146 | | - Returns: |
147 | | - The `f` callable. |
148 | | - """ |
149 | | - return self._add_callback(f, CallbackGroup.COND, expected_value=True) |
150 | | - |
151 | | - def unless(self, f: Callable): |
152 | | - """Adds a ``unless`` :ref:`guards` callback with expected value ``False`` to every |
153 | | - :ref:`transition` in the :ref:`TransitionList` instance. |
154 | | -
|
155 | | - Args: |
156 | | - f: The ``unless`` :ref:`guards` callback function to be added. |
157 | | -
|
158 | | - Returns: |
159 | | - The `f` callable. |
160 | | - """ |
161 | | - return self._add_callback(f, CallbackGroup.COND, expected_value=False) |
162 | | - |
163 | | - def validators(self, f: Callable): |
164 | | - """Adds a :ref:`validators` callback to the :ref:`TransitionList` instance. |
165 | | -
|
166 | | - Args: |
167 | | - f: The ``validators`` callback function to be added. |
168 | | - Returns: |
169 | | - The callback function. |
170 | | -
|
171 | | - """ |
172 | | - return self._add_callback(f, CallbackGroup.VALIDATOR) |
173 | | - |
174 | 100 | def add_event(self, event: str): |
175 | 101 | """ |
176 | 102 | Adds an event to all transitions in the :ref:`TransitionList` instance. |
|
0 commit comments