You can improve SearchScreen by applying the following;
- Do not pass the
ViewModel object down to its children. Instead, extract the data you need from the ViewModel and pass those data along.
- Make all other functions in
SearchScreen private to prevent namespace pollution.
ObserveCurrentTime is quite misleading because it does more than just time observation. It also emits UI components.
- You are exposing Mutable data types from your
ViewModel to the public. Normally, you would want your ViewModel to only expose states to the UI. The sequence of UI->VM usually goes along these lines;
UI: Observes state from the VM
UI: Invokes a function from the VM
VM: Performs an operation
VM: Updates a state internally and publishes to subscribers
UI: Receives new state updates and refreshes components accordingly.
You can improve
SearchScreenby applying the following;ViewModelobject down to its children. Instead, extract the data you need from theViewModeland pass those data along.SearchScreenprivate to prevent namespace pollution.ObserveCurrentTimeis quite misleading because it does more than just time observation. It also emits UI components.ViewModelto the public. Normally, you would want your ViewModel to only expose states to the UI. The sequence of UI->VM usually goes along these lines;UI: Observes state from the VM
UI: Invokes a function from the VM
VM: Performs an operation
VM: Updates a state internally and publishes to subscribers
UI: Receives new state updates and refreshes components accordingly.