Part 4 — State and Data [Mutable Fields]
In this part, you will learn how to change the values of state and data fields. And how they can be used in the application.
Last updated
In this part, you will learn how to change the values of state and data fields. And how they can be used in the application.
Last updated
Remember the Part 6 State Machine?
Let me remind you: in the example from Part 6,
we wrote the timer value in the state.timerValue
field.
Then we did not change the state value while the program was running.
But what if we want to change the value of the timer?
For these purposes, we have two types of fields
available:
state — for storing lightweight values
data — for storing heavyweight values
In order to use mutable fields while the application is running:
All required fields must be initialized before calling app.run
Fields keys must be written in CamelCase
register
data
fields can't read the values of widgets,
so for widgets you need to use state
src/main.py (partially)
To get
or set
field, we need to refer to the api
of the application.
Here's a simple example:
src/main.py (partially)
Let's run the app and take a look at our improved timer!