Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

feat: Remove @react-native-async-storage/async-storage dependency #29

Closed
509dave16 opened this issue May 23, 2022 · 5 comments
Closed

Comments

@509dave16
Copy link

This @react-native-async-storage/async-storage dependency is hard coded. I know that AsyncStorage API from react-native is deprecated. But if sovran-react-native could transition away from using @react-native-async-storage/async-storage then that would be one less dependency to install. Especially if a user/client is using a different store persistor that is not based on @react-native-async-storage/async-storage(e.g. MMKV): segmentio/analytics-react-native#549

I know there may have been reasons for transitioning away from react-native's api AsyncStorage. If going back to that would break functionality in some scenarios, then maybe we could either:

  1. Have default be an "in-memory" persistor like in this unit test here: https://github.com/segmentio/analytics-react-native/blob/1f960f04cc53fd8c3dbe07aa9edd05aa7cf388d9/packages/core/src/storage/__tests__/sovranStorage.test.ts#L109-L117
  2. Or make createStore's argument config of type StorageConfig be required as well as the persist sub-property of type PersistenceConfig and it's sub-property persistor. And then document how to use @react-native-async-storage/async-storage as a dependency. Could also document on how to use MMKV.
@gabrieldonadel
Copy link

@oscb @alanjcharles would you accept a PR adding the support for different storage providers instead of relying on @react-native-async-storage/async-storage? Something like https://github.com/apollographql/apollo-cache-persist/blob/master/docs/storage-providers.md.

If so I can open a PR adding this functionality.

@georgeilas-tem
Copy link

georgeilas-tem commented Sep 6, 2022

Hi,

We used the option storePersistor and created a custom MMKV persistor for segmentio/analytics-react-native, so theoretically sovran doesn't even use async storage anymore. But we can't delete the @react-native-async-storage/async-storage package from our project because it's hardcoded. It's a bit messy and inefficient to keep a package in the bundle that we don't use at all.

You mentioned a in-memory default persistor. Any news on this?

@georgeilas-tem
Copy link

Is this project maintained anymore?

@isaachinman
Copy link

To expand on @georgeilas-tem's solution, an MMKV store persistor can be written like:

const segmentMMKV = new MMKV()

export const segmentClient = createClient({
  storePersistor: {
    get: async <T>(key: string) => segmentMMKV.getString(key) as T,
    set: async <T>(key: string, state: T) =>
      segmentMMKV.set(key, JSON.stringify(state)),
  },
  trackAppLifecycleEvents: true,
  writeKey: config.segment.writeKey,
})

However, as @georgeilas-tem mentioned, we still need to keep @react-native-async-storage/async-storage@1.17.10 in our bundle, or else we hit NativeModule: AsyncStorage is null errors, despite not actually needing the package at all.

I see that this package hasn't been touched in 10 months, yet is still a mandatory requirement for @segment/analytics-react-native, which is actively maintained.

@oscb @alanjcharles Can you please provide a response on this issue?

@oscb
Copy link
Contributor

oscb commented Mar 13, 2023

This change was just merged: segmentio/analytics-react-native#779

This repository will be archived now. We migrated this into the analytics-react-native monorepo.

@oscb oscb closed this as completed Mar 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants