Search code examples
javaandroiddesign-patternsmvpflux

How stores objects update view in flux pattern


Imagine we have a chat application and conversation page has been opened. If one of messages edited by other user or message's state changed from sent to deliver, Action update Store with new messages metadata. For example,after these actions we have a list of messagesState or messagesText or simply messages with modified data in our Store . So in this scenario we don't know which row has been edited and we render all the data in view again. Is this behavior one of Flux principles? Isn't better to update and send event about updated object only?

( I developing Android application and so I don't use reactJS or other library like this)

Also I going to think it's good if we mix MVP with Flux! because if one view want to change itself we have to put logic in view.for example view directly get store data and check it belongs to which element! I think a presentation layout is good for this type of situation. Has anyone tried this?


Solution

  • So in this scenario we don't know which row has been edited and we render all the data in view again. Is this behavior one of Flux principles?

    Yes, it is! One of Flux principles is immutability of data, in order to avoid doing incremental change handling on every object in a parent data structure. This also immediately answers your second question:

    Isn't better to update and send event about updated object only?

    There are plenty of helper libraries for your Android project out there to establish immutable datastructures. To name just a few:

    In comparison, ReactJS is able to only perform updates on the "UI-Layer", the DOM, by comparing the current DOM tree to the to-be-updated DOM tree and therefore can perform incremental updates. You could mimic such a behaviour in your Android views, by implementing something analog to the shouldComponentUpdate() function of ReactJS for your views.