How to Update the model to trigger a view change.
See original GitHub issueI am using a OnModelClickListener
to add click listener on an imageView. I want to change the image when the view is clicked. I m little confused on how to achieve the same. How to change the underlying model data? Also, I don’t want to fetch all the data again. Should I change the image from the clicklistener itself? I am using a PagedListEpoxyController
. I don’t want to re-fetch the data again from the repository
.
override fun onClick(model: ItemCustomViewModel_?, parentView: ItemCustomView?, clickedView: View?, position: Int) {
val userName = model!!.post().publishedBy.userName
emmiter(if (model.post().publishedBy.following) FollowEvent(userName) else UnFollowEvent(userName))
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to cause an update of model to trigger a ... - Stack Overflow
I want when View Controller A updates the model, a method to be triggered in View Controller B such that the view is...
Read more >How to update the view when the model changes?
1 Answer 1 ... This depends on the life time of the view. For short-living views, it may be sufficient not to update...
Read more >Publishing changes from within view updates is not ... - YouTube
Publishing changes from within view updates is not allowed, this will cause undefined behaviourWant to learn about observable object and ...
Read more >6 Using Triggers
This tutorial shows how to use the CREATE TRIGGER statement to create a trigger, EVAL_CHANGE_TRIGGER , which adds a row to the table...
Read more >Trigger flows when a row is added, modified, or deleted
Use the Select columns box to define the specific columns of the row that should cause the flow to run when changed, as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You generally don’t want to change the view directly from the click listener - the model should be rebuilt and diffed, and the changes will be applied to the view.
The
PagedListEpoxyController
changes things though, since it maintains a model cache and doesn’t rebuild models created from the paged list - it was designed for the model to get all of it’s data from the paged list, and for data changes to only go through the the paged list, in which case models are automatically rebuilt when data changes.If you need to force the model to be rebuilt with outside data then I think you will need this - PagedListEpoxyController
I’ll try to get that merged soon
The pr to force clearing the model cache is merged