Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: Refresh data in view model

$
0
0

Hi,

In my opinion, using the EventAggregator to inform your view models of changes seems to be a reasonable approach as you would be able to communicate your view models with your repository in a loosely coupled way without using strong references. Also, besides the EventAggregator, Prism provides other approaches to communicate loosely coupled components that you could find interesting:

Regarding the approach of updating only the view models of the views that are visible, I believe it could be an interesting and useful method to increase the performance of the application. However, you will need to add some custom logic to determine when a view model should update its models or not. For example, if a new unit of work is available but the view is not visible, this means the view model will not be updated and thus, it has to be updated later when the view becomes visible again.

As you mentioned, you could use the INavigationAware interface in scenarios where the views are being navigated to and from. However, I believe you could also take advantage of theIActiveAware interface in order to know when a view / view model is active or not. Usually, a view is active when it's visible and inactive when it's not being shown. Hence, this interface could be handy to know when a view is visible or not.

Finally, about destroying the views when they are hidden, this is also a plausible approach. Although this approach is more resource demanding (as you mentioned) how much expensive it's will depend mostly of your application. If in your application the user will switch through a lot of views (that would be destroyed and re-created each time), the cost of this approach could be even higher than simply updating all view models regardless if they are visible or not. Hence, in my opinion, the previous approach seems to be a better choice.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini


    Viewing all articles
    Browse latest Browse all 1878

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>