feat(core): Introduce new API #1010
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This is an introduction to AsyncStorage v2. This is by no means the final shape, just something to spark a discussion.
Glossary
Core - Unified and concise API, extending Web Storage API with additional methods for multi-key manipulations. The main instance, AsyncStorage, is created by connecting it to a StorageBackend via call to AsyncStorageFactory.create
StorageBackend - Backing storage engine used by AsyncStorage instance. It provides basic methods to read/save and remove data. If the storage provides more capabilities than required, it can be exposed via Extension. The storage works on already serialized data (string).
Extension - additional functionality provided by StorageBackend on top of standard capabilities. This is heavily influenced by the capabilities of StorageBackend itself. One example could be providing information about storage size on disk.
Adapter - Serializes and deserializes provided data, before passing it to/from StorageBackend. As for now, a no-op adapter is used. In future versions, a user could provide their own StorageModel type and an Adapter for it (think of skipping all
JSON.stringify/JSON.parse
calls.Main changes
API separation
To expand AsyncStorage into different use cases, the storage has been separated from the core API. This means, that while the main API stays the same, the underlying storage engine will provide different capabilities, depending only on the implementation. From a user perspective, one API can be used to use different kinds of storage, such as file-on-disk, in-memory, SQLite, Encrypted, etc.
Getting AsyncStorage
Because of the separation, the main instance, AsyncStorage needs to be connected to StorageBackend. This happens via call to AsyncStorageFactory.create method, where user needs to provide an instance of StorageBackend.