Using redux with a local database

I have a standalone React web application where all data is stored locally in indexedDB. There is no other server than file hosting for static assets. I get to the point that I’m starting to learn how to use abbreviations, but I’m trying to understand the trade-offs between moving more data to the storage and continuing to use the database. What is the idiomatic way to use local db with reduction?

Currently, my application consists of several container components, each of which extracts data from db's componentWillMount. One option for integrating redux is to keep it basically the same, with the only difference being that the state is stored in the repository and the data is retrieved using actions and thunks.

Alternatively, I saw many examples of code that loads all the data into the repository at startup. This makes the entire application more deterministic, easier to test and play. Switching between the main components will occur instantly (due to the initial loading of the application). But I am losing the benefits that the database provides as indexes and nice queries.

It seems that this would be an unreasonable load on literally the entire db in the store, at least in my case, it would be about 10 MB of data, or maybe more. Therefore, I will always have at least some components that should continue to collect data on mount. But there is a subset of data that is central to the application, and it can be argued that the table must be loaded in its entirety (it will probably be from 5,000 to 10,000 objects).

What is the idiomatic way to work with local storage and reduction? I understand that asynchronous samples in componentWillMountare not idiomatic if they can be avoided. Even in cases where the state is small enough to be fully loaded into the store, is it worth giving up the benefits of a good efficient query interface?


Edit: I have to mention: I use Dexie , which is a really great library for working with indexedDB. It is fast, has a nice query interface, handles migrations, etc. I would really like to continue using Dexie if there is no really strong reason for this.

Dexie github. , " ". , , , .

+4
2

, . , , .

TL; DR: . , , - , . , . .

( "Building React Applications Idiomatic Redux" ) ( ) .

, , , . , , .

@seanyesmunt, -persist, .

, API. , API - IndexedDB, . , , .

, Dexie Redux. , thunks DB .

+4

, dexie , . , Graphql , . /dexie. , graphql , "" (backend store) dexie, . grapql Apollo Facebook, , , .

, , db . , , . Graphql.

+2

Source: https://habr.com/ru/post/1680920/


All Articles