-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_model.py
More file actions
25 lines (16 loc) · 968 Bytes
/
view_model.py
File metadata and controls
25 lines (16 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""View model implementation for complex Pydantic rules example."""
from typing import Any, Dict
from nova.mvvm.interface import BindingInterface
from .model import Model
class ViewModel:
"""View model implementation for complex Pydantic rules example."""
def __init__(self, model: Model, binding: BindingInterface) -> None:
self.model = model
# self.on_update is called any time the view updates the binding.
self.form_data_bind = binding.new_bind(self.model.form, callback_after_update=self.send_cleaned_text_to_view)
def send_cleaned_text_to_view(self, results: Dict[str, Any]) -> None:
# This is necessary to send the cleaned text to the view since it's updated programmatically.
self.form_data_bind.update_in_view(self.model.form)
def update_form_data(self) -> None:
# This will fail if you haven't called connect on the binding!
self.form_data_bind.update_in_view(self.model.form)