question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to Update the model to trigger a view change.

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
elihartcommented, Jan 3, 2019

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

0reactions
elihartcommented, Jan 12, 2019

The pr to force clearing the model cache is merged

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found