How to handle states with redux and realm [react-natve] - mongodb

I'm working on a complex application using react-native, and I'm struggling on how to manage states and persist-states.
I'd like to achieve something like instagram, loading posts one time in redux and then save a bit of them in local-memory, to show something when the user open the app without internet connection.
Now to handle states across the app I'm using react-redux even if it cause some lag on react-navigation transition, and to save data locally suggest me to use redux-persist for low-complexity apps and realm for medium/hight-complexity apps.
What's exactly the practical difference between redux and realm?
(excluding the fact that the former doesn't persist when app is closed).
Is it right to use both redux and realm? If so what's the best implementation?
Thank you.
Please no useless question, I've been clear.

I am also working on messaging app (consider complex app?) and here is my answer to your question.
Redux is state management library and Realm is just database solution. I guess you are trying to say redux persist/asyncstorage. redux persist allows you to store key-pair value in your app while realm is way more efficient when storing large amount of data.
Yes, it is right to use redux and realm together. Redux is used as state management, managing all the UI state, while Realm is served as database to store your data.
Example (Messaging App)
When load messages from API, store it in realm directly.
Add a listener for realm, listen the data changes and expose them in redux state.
You may whitelist/blacklist your state in redux persist by destroy these state when you killed the application.
Here is my small explanation.

Related

Is Hydrated Bloc good for storing more complex data?

I'm a newbie in flutter and recently started learning Bloc with flutter_bloc package. I want to store some data in local storage.
I have found the hydrated_bloc package, and here comes my question: "Is HydratedBloc good to store more complex data (like: users list, their details, saved todos, notes etc.) Or it's just created to persist simple state data (like: chosen theme (dark or liqht), last page where user left)?".
How can I best store data localy when using bloc?
Yes, You can use it to store complex data. Because, As the package itself states that it is built on top of hive for a platform-agnostic which is faster than shared preferences.
You can take a look at the image below to see the difference.

Rest API data stored in locally - Flutter

I have a requirement to store data locally to use within a Flutter mobile application. This stored data will be used for when the device is offline and will need to be updated, whilst offline.
On initial login of the application, data must be pulled from a REST API and stored locally to be displayed within the app.
Does anyone have any pointers as to what is the best method for this? I've looked at Sqflite but i can't seem to see any tutorials or documentation on setting this up using an API to 'fill' the data initially.
Any advice would be appreciated.
There are many ways to go about this.
One option is simply using dio, which has caching support built in.
Or, you could use something like hive or SharedPreferences along with http to to persist the data yourself (depending on what level of control you want/need).
You could also encapsulate the data in a state management solution like riverpod (specifically a FutureProvider in this case) which will soon have offline persistence support.
If building an application from scratch, I'd recommend the riverpod route (and it will soon have that offline persistence support).

What to use ? Bloc or Moor in Flutter

So, I am trying to create a project where I am supposed to Call Web API and store the data in my local storage. Which should still have even if the app is killed and then re-opened.
FYI, data will be large and I will require a significant amount of space in the mobile device.
i will be using firebase for login, the payment transaction and etc.
this is my first answer, I hope to help you.
BloC & Moor are not synonyms, BloC is a reactive state management solution that allows you to better manage the interaction between logic and widgets in a reactive way. Moor is a layer between sqlite and your application, it allows you to deal with sqlite using dart code by reacting to database changes through Streams and Futures
I think you do not need to choose one of the two, if your application is going to handle large amounts of data and will grow exponentially I recommend that you implement both as they complement each other, by designing a SOLID structure.

Store CoreData in iCloud

I am currently creating a macOs application that stores customer data in a CoreData database.
Now I want that data to be stored in the iCloud. The idea is that every user has its own data in his iCloud. If he uses more than one Mac/iOS device he can access his data.
So I don't a centralized data storage for all customers but a data store for each customer separately.
I have read through some topics regarding CloudKit but was confused about it in general:
CloudKit provides a data storage for global data (e.g. I want to store data of customer)
Is there a possibility to story CoreData to an iCloud account of every customer?
If so is this possible by CloudKit or do I have to use a third party lib like Ensembles? (That mentioned there was a thread of 2016 saying that Apple dismissed the possiblity to use CoreData via iCloud but only 3rd party libs like Ensemble would work now)
Can someone give me his experience in this?
Thank you
CloudKit is quite extensive. It provides three types of database:
Public, which can be shared by everyone.
Private, which is specific to one iCloud account.
Shared, which is someone's private database, but which you have been given access to.
This gives you plenty of options, and the case you are asking about, where data is shared between the devices of a single iCloud user, fits nicely into the private database. In other words, CloudKit would work very well for you.
As others have already stated, CloudKit provides you the online storage you need to move data between devices, but it doesn't provide a complete mechanism for that. That is where frameworks like Ensembles come in; they are built on top of CloudKit and other services to handle all the bookkeeping involved in keeping two devices separated in time and space in sync. (Disclaimer: I am the developer of the Ensembles framework.)
You don't have to use a framework like Ensembles; you can just communicate with CloudKit directly, but you should not underestimate how much time and skill it would take to develop a fully syncing app with Core Data. Depending on your dataset, there can be a lot of gotchas. Ensembles and similar frameworks do a lot for you:
Ensuring changes are played back in the same order on every device
Handling concurrent changes on two different devices
Removing old and redundant data
Keeping memory usage low by providing batching, which is very important on iOS
In short, you can do it yourself, but I wouldn't recommend it. If you want Core Data sync, I recommend Ensembles, or to look at other libraries like Seam (I have not used this, but it seems popular).
If you are not married to Core Data, you could look at options like Realm and Firebase, which effectively handle the sync problem and the client API in one hit.

use custom core data persistent store for getting data via webservices?

Is this a good idea? When is it a good idea, and when is it bad?
Just heard about this in one of the WWDC videos, and I don't quite understand why would one want to do it this way. Seems complicated and I cannot see the benefit.
The way I see it, it would be to totally abstract the data access layer. You'd then be able to access the web service using Core Data fetch request API. You'd also be able to implement caching in the persistent store without affecting the application logic.
Also changing the web service request/response format could potentially only affect the persistent store layer.
I see it can be a benefit for large requests. Since networking is quite expensive in battery life, application should use as less bandwidth as possible so developing a single request sending more information but using Core Data to access only subsets at a time is a good design in my opinion.
Finally, I think Core Data API blends well with major ORM web framework like rails or django for example.
It is complicated and it is meant to show what you can do with Core Data. I personally like to keep server communication separate from the local cache and then update the server based on changes to the local cache. This means that I use code that listens for save events from Core Data and then updates the server.