epoxy icon indicating copy to clipboard operation
epoxy copied to clipboard

Epoxy attribute fields on a model cannot be changed once the model is added to a controller. Check that these fields are not updated, or that the assigned objects are not mutated, outside of the buildModels method. The only exception is if the change is made inside an Interceptor callback. Consider using an interceptor if you need to change a model after it is added to the controller and before it is set on the adapter. If the model is already set on the adapter then you must call `requestModelBuild` instead to recreate all models.

Open ElieBouNader opened this issue 5 years ago • 11 comments

i did everything and this issue still existing, any idea?

ElieBouNader avatar Dec 23 '20 13:12 ElieBouNader

Please, does anyone faced this issue???

ElieBouNader avatar Jan 07 '21 16:01 ElieBouNader

You can't change of of any variable on bind method on controller class.

hm-tamim avatar Feb 14 '21 11:02 hm-tamim

What's the issue to begin with? What are you trying to accomplish?

The error message is quite self-descriptive, and it's telling you that you aren't supposed to mutate nor update models manually after they were added to the controller, but instead either use an interceptor or call requestModelBuild (which will diff and update the specific model that changed for you).

mradzinski avatar Mar 16 '21 16:03 mradzinski

@mradzinski I am also facing this issue and I am using requestModelBuild() function after updating item at position 0. If this is not correct way then can anyone here tell what is the best way to update any item and notifying epoxyrecyclerview. I am using kotlin databinding

adrielAd avatar Apr 08 '21 09:04 adrielAd

I would love to see a use case of using an "interceptor", the docs do not say much about it.

Draketheb4dass avatar May 14 '21 21:05 Draketheb4dass

i found the solution. the data that you added to epoxyModel_. you have not to modify directly. so, if you use kotlin, you can create new reference of that model and requestModelBuild() again.

to create new reference, you can use copy() or if it is the collection, use toMutableList() / toList()

for example, inside EpoxyController:


var myModel: MutableList<WhateverModel> = mutableListOf()

override fun buildModels() {

myModel.forEach {
MyEpoxyModel_()
    .id(R.id.epoxid)
    .whateverModel(it)
    .onBind { model, view, position ->
                 view.cardView.setOnClickListener {
                     val modelCopy = model.whateverModel.copy()
                     modelCopy.anyAttr = "this is what i changed"
                     
                     val index = myModel.indexOf(model.whateverModel)
                     myModel[index] = modelCopy

                     requestModelBuild()
                }
            }
    .addTo(this)
}
}

wiztensai avatar Jun 30 '21 07:06 wiztensai

i have a social feed screen in my project that i used epoxy for listing posts. users can like or unlike posts. i'm facing this issue when the new posts are added to pagingcontroller.

is there any way?

kdgr avatar Sep 15 '21 09:09 kdgr

I was facing the same issue yesterday. Now I managed to solve it.

TL;DR The data for epoxy have to be different with the data source.

So, what I do is:

  1. Create source data and store in ViewModel.
  2. Create a copy of source data every time epoxy requestModelBuild()
  3. When I want to change the data of an item, I call the function in ViewModel to make change on the source data.
  4. call epoxy recyclerview to requestModelBuild

nmhung avatar Sep 18 '21 09:09 nmhung

Update your Model(Data class) and submit data, this will update the item that you want to update.

override fun buildModels() {

        UserModel_()
            .id(user.id)
            .name(user.name)
            .onClickListener { model, parentView, clickedView, position ->
                user.name = "New updated name"
                setData(user)
            }
            .addTo(this)
    }

jimale avatar Oct 15 '21 20:10 jimale

@jimale Can you share a sample?

ghost avatar Nov 17 '21 06:11 ghost

In my case, I changed the priority that flag by @EpoxyAttribute when the bind holder run. so i try to new a local object copy from origin priority ,and render view use local object . wish this help you

MoneyQianN avatar Jun 04 '24 08:06 MoneyQianN