Abed shmaytilli
Abed shmaytilli

Reputation: 113

LiveData, is it possible to observe specific value

I am using live data to sync qty change between duplicate items on the same view. So if there are 7 items observing qty updates, and 3 of them have the same ids, if one of them is triggered all of the 7 will follow even though 3 of them should be refreshed.

My question is, would it be possible to subscribe to a specific value, instead of the whole field kind of like a topic subscription just so that those 3 items with the same id would only be triggered

Upvotes: 0

Views: 769

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317913

When you observe a LiveData, your listener will get all updates to the object stored in the LiveData with every update. It's not possible to tell a LiveData to be "smart" about which specific nested values you want.

If you want to transform the object inside the LiveData into a different object that meets your needs, you can use Transformations.map() to create a new LiveData based on the contents of the one you have now. It will be up to you to make sure the code only generates new LiveData objects if something of interest changes in the original.

Upvotes: 1

Related Questions