Thank you for the article.
Reza Shah

Hi, thanks for asking.

Let me give your some insights regarding why I decided to publish the whole state (in this case the whole Cart).

As you mention, I could have publish one element at the time (the last modified one). But for me this give you less flexibility and could lead to subtle bugs. In my code, I had two parts of the UI “listening for changes”, the Cart screen and a counter. If I was posting a single element, then each should have their own internal state and then modify it after each new event. So in the case of the counter, after each published event it should know how many were there before.

Another possible problem could be screen rotations. Imaging that we rotate the screen, in that case, after subscribing both element would get the entire Cart, so they do not need to worry about previous states. But in case we were posting only the last element added to the Cart, then each UI elements should have save their previous state.

If you are worry about performance, you could use something like RecyclerView DiffUtil, so by the time you update the UI, only the modified cells will be really updated.

I hope it helps!