49
Views
6
Comments
Solved
How to sync an entity to local storage partially on initial? (Mobile app)

Let's just say i want to synchronize several records when i logged in to the mobile app for the better performance. The records that being synchronize is the 30 first records, and it's going to be appear in the home screen as a list. And then when on the scroll ends, i need it to be synchronized again for 10 records each scroll.


The question, how to implement these flow as i mentioned above? As far as i remember, the offlinesync action is for synchronize all of the entity records, not partial.

mvp_badge
MVP
Rank: #19
Solution

Hi Aditya,

The Sync Framework in OutSystems always runs in the background (I believe there's references to that in the online training, likely here and here).

Sync happens at very specific moments: on user login, when the app resumes after the user switched to another app on the device and when the device comes back online. You can also explicitly trigger the sync (review the Local Storage lesson and exercise), but you don't have that much control over when it starts or how long it takes. You can however be notified when the sync finishes.

Since syncing always happens in the background, it has no direct impact on the user's interaction with the app itself (only with the new/fresh data that may be presented to the user).

Using the JavaScript equivalent to timers (check the setTimeout()/clearTimeOut() or setInterval()/clearInterval() methods, depending on what your goal is), you can have your app regularly trigger the sync but, as a general rule of thumb... you probably don't want to.  

Also, you can decide to sync partially your data, by using the SyncUnit input parameter to "identify" a unit of synchronisation. How you use SyncUnit input parameter is up to you, but it will be passed around by the framework so every sync piece of logic you implement can be aware of it, and can use that info to decide what data to sync.

Hope this helps!

mvp_badge
MVP
Rank: #18

Hi Aditya,

You can implement any sync logic you want. For sure there is no obligation to synchronize all of the entity records.

Regards,

Daniel

mvp_badge
MVP
Rank: #2

Hi Aditya,

You really don't want to sync when the scroll ends, because this means the user has to wait for a considerable time, which is very user unfriendly. The whole idea of syncing is that you have all the relevant data locally, so the user does not have to wait.

mvp_badge
MVP
Rank: #2

Hi Aditya,

  1. For a mobile app, it is recommended to always sync the data if possible, as that will result in a better user experience. Waiting for the server leads to slow-downs.
  2. Synchronizing can be done in the background, so there's no need for the app to slow down.


mvp_badge
MVP
Rank: #19
Solution

Hi Aditya,

The Sync Framework in OutSystems always runs in the background (I believe there's references to that in the online training, likely here and here).

Sync happens at very specific moments: on user login, when the app resumes after the user switched to another app on the device and when the device comes back online. You can also explicitly trigger the sync (review the Local Storage lesson and exercise), but you don't have that much control over when it starts or how long it takes. You can however be notified when the sync finishes.

Since syncing always happens in the background, it has no direct impact on the user's interaction with the app itself (only with the new/fresh data that may be presented to the user).

Using the JavaScript equivalent to timers (check the setTimeout()/clearTimeOut() or setInterval()/clearInterval() methods, depending on what your goal is), you can have your app regularly trigger the sync but, as a general rule of thumb... you probably don't want to.  

Also, you can decide to sync partially your data, by using the SyncUnit input parameter to "identify" a unit of synchronisation. How you use SyncUnit input parameter is up to you, but it will be passed around by the framework so every sync piece of logic you implement can be aware of it, and can use that info to decide what data to sync.

Hope this helps!