Skip to content

How to handle mobile data update

Background

In PlatformHub, a domain model plugin provides a single source of truth of data. View plugin(s) and other domain plugin(s) would consumse it

uni-direction data flow

Case Study

Let's take balance visibility for example: When the costumers turns it on, the balance is visible, otherwise it is hidden. Usually it is also a requirement to persist its value locally and in the server side, so the value is kept between app launches and also if the user switches to another device. Thus the visibility toggle published by the domain model is a combination of these scenarios with a default value to true (meaning the balances are visible).

Possible Solution

When customer toggle on or off of this on the view (view plugin), we choose to have it notify domain model plugin for the data to be updated and leave it to the domain model plugin to handle the following :

  • Communicate with related repositories (via capability plugin) for the data update request and result handling.
  • Retrieve and publish the updated value to all subscribers including the one initiates the update request.

These are the consideration comparing the update initiated from between view plugin and domain model pluin: If it is the view plugin to handle the data update directly :

  • It could be lacking sufficient information to submit update action for the reason mentioned above the transformation and as view model should only holds fields that used for UI and the the field being updated might not be a valid parameter placeholder for the API call.
  • It introduce extra responsibility for a view plugin which make it heavy weight to maintain as it need to have API configuration for network and handle the API call and then handle the result of either success or failure and then request domain plugin for force refresh of data.

On the other side, if it is the view plugin to send message to the domain model plugin and leave it to handle the update :

  • It releases view plugin from having this extra data manipulation responsibility and move it to a more data concerning module which is the domain plugin
  • It can make the update action be sensed by the domain data owner component more quickly to take corresponding action ,than view plugin to taking other detouring.
  • Domain model plugin is more close to API calls and hosting API endpoint parameters already for data requesting.
  • Domain model plugin has/could have sufficient data to assemble the network call as it consumes the API response of raw data.
  • Once the data has effectively changed, the domain model would broadcast the new state of the data and multiple components in the app could react to this chage i.e. updating several views at the same time.

Flowchart

mobile data update