-
Notifications
You must be signed in to change notification settings - Fork 473
[RFC] Async Storage v2 #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One feedback I have is that since the public API and the storage backend API have 1:1 mapping, it'll be better not to have different naming for them and have the same API for less cognitive overhead. Though it also begs the question, if the storage backend and the public API have the same methods, then what'll be the advantage of Regarding the storage backend for web, instead of |
If we are going to completely break the public API, I would suggest that we look for API compatibility with the |
This sounds good! I have one question and a couple of comments: Maintaining backwards compatibilityCould the new public API be implemented without completely breaking older code? I did this with the NetInfo module by checking the type of the parameters and falling back to old behaviour if needed. This should help smooth out the adoption of the new version as it will be less of a problem if two libraries depend on AsyncStorage and one hasn't been updated. It's more work to do this, but is much nicer for users of library. You can see a chunk of the NetInfo compatibility code here: Using
|
Thank you all for the comments and suggestions! @satya164 I've left names different to explicitly distinguish public API from Backend API, for cases like calling Storage directly (not through AsyncStorage API). @3rd-Eden As @matt-oakes said we have methods to do operations on more than one data (multi @matt-oakes I think that adding the factory is already a big breaking change, but we could add support for old methods name (like thanks. |
Awesome idea! I would go with monorepo with current implementations for Android / iOS. We can let people create their own implementations, but let's provide bottom line for people who don't want to do this. I agree with @satya164, making explicit distinguish sounds good, but why do we want to change public API? I would change the Backend API method names, not the Public API if they must be easy to differentiate. Good direction for improvements! I will keep my fingers crossed. |
I like the idea, tough I'm against having backward compatibility as a prime idea. We are talking about a new major version of Async Storage, so it is fine to change API. IMO the public API that kv-storage has is better that the current Async Storage API - for instance That being said backward compatibility is a important feature for some people, so IMO it is better to have it as a opt-in in factory - there could be |
I love the idea to use SharedPrefernces and NSUserDefaults. I really do not need SQLite to save key-value settings. Also I think it is nice pointing out that with the
In favour of having some storages available. -- /*
* expected to return all keys used to store values
*/
getStorageKeys(options?: AsyncStorageOptions): Promise<Array<string>> {}
/*
* expected to clear all stored data in storage
*/
removeWholeDataFromTheStorage(options?: AsyncStorageOptions): Promise<void> Is the |
@pbitkowski @zamotany I want public API to be as clear as it can get. I'm fine with @ferrannp I'm fine with Regarding backward compatibility, I was thinking about providing
|
Will the Re: |
Great work on the RFC, I really like that. One question - what do you think about supporting JavaScript objects by default and letting the backend to decide whether they want to serialise it entirely or not? Doing JSON.parse/JSON.serialise is not a big deal, but I feel like moving this responsibility over to storage backend would allow for more performant storage (if backend supports objects) and more expressive interface for setting and accessing values. |
@grabbou The main assumption is to let Storage decide what to do with given data (serialize it or not, modify it somehow, etc.). Thank you all for the feedback. I'll do adjustments to API and add necessary details so we could begin the work soon. thanks. |
I'd love to see two things:
Clearing the store is an operation nearly every app should include if there's any kind of logout function. It would be great to clean up how this operation is done. |
I've updated the API a bit. Going to create a GH Project, so progress can be tracked down. |
Plan to start v2:
Going to start working on this later this week. |
Is there a plan/discussion of using CoreData's SQLite on iOS? (Worked in similar issue a few days ago and made me wonder about it) |
@sidferreira The good thing about this RFC is that it allows you to create your own Storage solution and use it with Async Storage - you just need to apply an interface. |
Is there any timeline in mind? |
Doing this in my free time, so trying to squeeze in as much as I can. Sorry, no timeline in mind just yet |
LMK how to help (I still have to read all issues about this, maybe I can figure out of it...) |
Hello! Few things listed there:
This list reminds me about Dataloader, which has browser support. |
I'd suggest implementing / "subclassing" the public See
So that JS code can easily target both react-native and [react-native-]web . |
Does v2 has any solution for 2mb cursor limit? I have tested in different android phones, I think the issue is only in devices with android < 8. Nexus 5 with android 6 has the issue and s9 with android 9 works fine. |
@gamingumar Plan is to move the current AsyncStorage implementation into v2 (named as Legacy storage), so you won't lose your data once you upgrade. Reimplementing the Legacy storage is something that needs discussing, so that it would cover most of the cases other devs are facing. |
Hi guys, In short, This result is achieved by combining:
|
Why not make getMultiple return an object instead of an array?
|
I agree that |
@Sofianio
@denkristoffer |
@krizzu I just think it might not be worth changing the method names for a slight API improvement if it means breaking compatibility with every library that works with the existing |
@krizzu Then why not make |
@krizzu Can we set AsyncStorage location for iOS now? I didn't see anything on it in here or might have missed it out. Please suggest. |
Can't use with |
This still happens, and has not been fixed, it just doesn't show a "Red"/Error screen any longer. I see a warning being logged and a white screen. In the log it will say: [TypeError: undefined is not an object (evaluating 'this.error')] With a trace pointing to a library file. I'm only using |
@kennetpostigo |
const magic = await storage.get('@magic-link') |
@kennetpostigo Could you open a new issue describing this problem with repro steps? Thanks in advance. Thanks everyone for this conversation. It's been a long time since I started this and due to the fact that v1 also needs active attention for development, I'm putting v2 on hold. It's still open for PRs/suggestions, but I'm going to be less active for this part of AsyncStorage. |
Async Storage v2
Motivation
A few months back, due to the lean core effort,
Async Storage
was moved to a standalone repo, making it more open for bug fixes and feature implementations. By adding semantic-versioning, we've made sure that releases happen more often, keeping the library in a good shape.One of the discussed topics among the community was adding support for out of the tree platforms, so in a case where you have multi-platform project (say, Web app and RN app, sharing components and/or business logic), you don't have to use two different libraries for persisting data.
In a new major release, I'd like to introduce a concept of replaceable storage backends, making Async Storage more open not only to other platforms but also to other storage implementations.
Main changes
Current
Async Storage
is strictly coupled with its storage implementation (SQLite
for Android and serialized dictionary/files for iOS). The replaceable storage feature would give you the ability to use adequate storage for a given task - think of using Shared Preferences for simple key-values, while still being able to useSQLite
database for larger data, using the same API.Key benefits :
Implementation
There are three main parts of this feature:
Async Storage Factory
This factory class creates an instance of
AsyncStorage
with selected storage set. You can pick storage used based on platform or other condition.Creation of Async Storage can be enhanced by passing
FactoryOptions
options. Features such as logging can be set up here (added later, over time).Public API
Supported actions are
write/update
,read
anddelete
.Promise based API (no callbacks). This is mainly to focus on one API model and leverage Promise API (
callbacks
could be implemented throughAsyncStorageOptions
).AsyncStorageOptions
is optional config passed down to storage implementation. Type is dependent on storage used.Storage Backend API
AsyncStorageBackend
interface (Common Storage API
on the diagram) must be applied by any Storage Backend in order to be valid. Those methods are called byPublic API
, passingoptions
down.As an example, where's how Storage Backend would look for a Web (using
localStorage
):Other changes
Migration to Typescript (keeping support for Flow)
Monorepo (see questions below)
TBD.
Questions
API (both public and common storage)
Do we plan to maintain Storage Backends in the main repo? If yes, should we move to monorepo?
The text was updated successfully, but these errors were encountered: