textual.reactive
This module contains the Reactive class which implements reactivity.
Initialize ¶
Reactive ¶
Reactive(
default,
*,
layout=False,
repaint=True,
init=False,
always_update=False,
compute=True,
recompose=False,
bindings=False,
toggle_class=None
)
Bases: Generic[ReactiveType]
Reactive descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default |
ReactiveType | Callable[[], ReactiveType] | Initialize[ReactiveType]
|
A default value or callable that returns a default. |
required |
layout |
bool
|
Perform a layout on change. |
False
|
repaint |
bool
|
Perform a repaint on change. |
True
|
init |
bool
|
Call watchers on initialize (post mount). |
False
|
always_update |
bool
|
Call watchers even when the new value equals the old value. |
False
|
compute |
bool
|
Run compute methods when attribute is changed. |
True
|
recompose |
bool
|
Compose the widget again when the attribute changes. |
False
|
bindings |
bool
|
Refresh bindings when the reactive changes. |
False
|
toggle_class |
str | None
|
An optional TCSS classname(s) to toggle based on the truthiness of the value. |
None
|
TooManyComputesError ¶
Bases: ReactiveError
Raised when an attribute has public and private compute methods.
reactive ¶
reactive(
default,
*,
layout=False,
repaint=True,
init=True,
always_update=False,
recompose=False,
bindings=False,
toggle_class=None
)
Bases: Reactive[ReactiveType]
Create a reactive attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default |
ReactiveType | Callable[[], ReactiveType] | Initialize[ReactiveType]
|
A default value or callable that returns a default. |
required |
layout |
bool
|
Perform a layout on change. |
False
|
repaint |
bool
|
Perform a repaint on change. |
True
|
init |
bool
|
Call watchers on initialize (post mount). |
True
|
always_update |
bool
|
Call watchers even when the new value equals the old value. |
False
|
recompose |
bool
|
Compose the widget again when the attribute changes. |
False
|
bindings |
bool
|
Refresh bindings when the reactive changes. |
False
|
toggle_class |
str | None
|
An optional TCSS classname(s) to toggle based on the truthiness of the value. |
None
|
var ¶
Bases: Reactive[ReactiveType]
Create a reactive attribute (with no auto-refresh).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default |
ReactiveType | Callable[[], ReactiveType] | Initialize[ReactiveType]
|
A default value or callable that returns a default. |
required |
init |
bool
|
Call watchers on initialize (post mount). |
True
|
always_update |
bool
|
Call watchers even when the new value equals the old value. |
False
|
bindings |
bool
|
Refresh bindings when the reactive changes. |
False
|
toggle_class |
str | None
|
An optional TCSS classname(s) to toggle based on the truthiness of the value. |
None
|
await_watcher
async
¶
Coroutine to await an awaitable returned from a watcher
invoke_watcher ¶
Invoke a watch function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
watcher_object |
Reactable
|
The object watching for the changes. |
required |
watch_function |
WatchCallbackType
|
A watch function, which may be sync or async. |
required |
old_value |
object
|
The old value of the attribute. |
required |
value |
object
|
The new value of the attribute. |
required |