Data will be passed to the view layer


Tips for implementing MVVM The MVVM design pattern was created with many factors in mind. Google being the mecca for implementing. This design pattern, has created many APIs and special documentation to help developers implement it. However, in field practice, we can still see many errors that will make the implementation ineffective and may even lead to interruption or even damage to the application process being developed. So, what common mistakes do we see and what steps can we take to overcome them? Let’s discuss them one by one. Separation of event and observer data There won’t be much problem executing the above code and the data will be displayed successfully. The problem arises when there is a change in behavior in the application.

Such as a change in orientation

Where the data that has been displayed is lost because the data request is issued again and waits for the data request to complete execution. To solve the above problem, just separate the function that requests the data and the object you want to observe, as shown whatsapp number list below. c The above code is normal and has no issues. But what if the data is only displayed when an event is raised? For example, when a button is clicked. Some situations where observing functions are called are shown below. Using the above code we can avoid creating Observe instances over and over again. Utilize the state of your data The final tip is to use state data. Eits, but before we leverage state data, what kind of situation do you want to solve? Let’s take a look at the following example of ViewModel class.

The code above looks fine


Whatsapp Number List

However, imagine if there was a lot of event and observer data in it. Without seeing the code, you must have imagined what the code will look like. As application development progresses, this will become very complex and potentially introduce errors. Those of us involved in BLB Directory development will find it difficult to maintain the complexity of the code inside. If you imagine this happening, we need to leverage data state. The data here refers not only to the information that users will search for and read, but also includes loading status, error messages, etc. Utilizing data state is very simple, we just need to create a class as a container to hold all the information as shown below.

Leave a Reply

Your email address will not be published. Required fields are marked *