launchdarkly / js-core

LaunchDarkly monorepo for JavaScript SDKs
Other
12 stars 12 forks source link

Provide an option to set custom storage #436

Open artyorsh opened 2 months ago

artyorsh commented 2 months ago

Is your feature request related to a problem? Please describe.

In react-native, the SDK uses @react-native-async-storage/async-storage package without an option to specify a custom destination for SDK keys. This mixes app-related keys with SDK keys, which is especially painful when migrating to a different library (say, MMKV). This also blocks apps from removing async-storage dependency.

Describe the solution you'd like

import { AutoEnvAttributes, ReactNativeLDClient, LDStorage } from '@launchdarkly/react-native-client-sdk';

const customStorage: LDStorage = {
  getItem: (k) => { mmkv.get(k) },
  setItem: (k, v) => { mmkv.set(k, v) },
};

const client = new ReactNativeLDClient(
  'mobile-key',
  AutoEnvAttributes.Enabled,
  { storage: customStorage },
);

Describe alternatives you've considered

Providing a documentation on what keys are stored by SDK would also work, giving an option to filter async-storage.

yusinto commented 2 months ago

We will investigate this. Internally logged 240413.

angelo-hub commented 2 months ago

+1 on this, we try to use mmkv for everything