Here, we'll see the implementation of the incr project, which we already saw how to build and use. The only dependency is on the Yew framework, and so, the TOML file contains the following line:
yew = "0.6"
All the source code is in the main.rs file. The model is implemented by the following simple declaration:
struct Model {
value: u64,
}
It just has to be a struct that will be instantiated by the framework, read by the view, and read and written by the controller. Its name and the name of its fields are arbitrary.
Then the possible notifications from the view to the controller must be declared as an enum type. Here is that of incr:
enum Msg {
Increment,
Reset,
KeyDown(String),
}
Also, here, the names are arbitrary:
- Msg is short for message, as such notifications are in a sense messages from the view to the controller.
- The Increment message notifies a click on the Increment button.The Reset message notifies a click on the Reset button.
- The KeyDown...