composeui.core.reactivity

Reactive methods: view methods that run again when a view field they read changes.

exception composeui.core.reactivity.ReactiveLoopError[source]

Bases: RuntimeError

A reactive method set a field that it reads, or methods kept changing each other.

composeui.core.reactivity.reactive(method)[source]

Run this view method again each time a view field that it read changes.

The application runs it once when the app starts, after setup_model, and records the fields that it reads. A run records them again: a branch not taken isn’t an input. A Task’s state is an input too. An event, such as the callbacks of one signal, runs it once after the event, with the other methods in the order they started. The method must not set a field that it reads. Slow work goes to a task’s Task.start_latest.

Parameters:

method (Callable[[_ViewT], None])

Return type:

Callable[[_ViewT], None]

composeui.core.reactivity.reactive_inputs(view)[source]

Get the inputs that each reactive method of view read in its last run, to debug it.

By method name: a field as its path from view, e.g. filters.hour.value, and a task by its function’s name.

Parameters:

view (View)

Return type:

dict[str, list[str]]

composeui.core.reactivity.start_reactions(root)[source]

Run the reactive methods of root and its children once, recording their inputs.

The application calls it. A view set later in a field of a started view, e.g. a list’s item, starts its own. A method started already isn’t run again.

Parameters:

root (View)

Return type:

None

composeui.core.reactivity.stop_reactions(root)[source]

Stop the reactive methods of root and its children: forget their inputs.

A web session stops its main view’s when it ends, and a view removed from a started view’s field stops its own.

Parameters:

root (View)

Return type:

None