Explore the features

React to meaning, not just clicks.

A dataController connects an event or a Data dependency to the behavior it should trigger.

A guided reading · 2 min

Why a controller is useful.

A page may need to respond when a name changes, when a person clicks a command or when a timed refresh is due. A controller makes that trigger part of the Source declaration. Named arguments make the relevant Data visible next to the behavior.

The declaration puts the trigger and its inputs in one place. The same Data model used by the views drives the behavior.

Read a click declaration.

Here the button has one nested controller. A click invokes the named Logic method with the current total. Because total uses =, a change to total alone does not invoke the action. The save method is application code that must exist in the page’s Logic; this declaration does not create a persistence service.

Python · explanatory excerpt
button = root.button("Save")
button.dataController(
    func="save", total="=.total"
)

Read the explanation here. The working lesson and full contract are linked below.

React to changes and control timing.

Caret arguments can run a controller on Data changes. _delay debounces execution; _onStart runs it when the page is ready; _timing specifies repetition in seconds. These controls let the declaration express when work is useful. Removing its Source stops its timers and registrations.

For a search preview, a delay can avoid running after every keystroke. That is timing control, not a network retry queue. Requests themselves belong to the RPC mechanism.

Keep a calculation small and an action explicit.

If the goal is to derive one value, use dataFormula. If it is to call an endpoint, dataRpc already supplies that relationship. Use a controller for the behavior that remains, and give reusable methods meaningful names.

The gallery also demonstrates _userChanges. Despite the name, it filters the changed path; it does not distinguish a human edit from a programmatic write.

A common surprise

Will changing total run the Save action in the excerpt?

Reveal the explanation

No. The equals pointer reads total at execution time. The button click supplies the trigger.

Try the working example and read the full contract

Open the Python lesson (c02) ↗
Official documentation ↗