Skip to content
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

React Native for Web? #15

Open
k2on opened this issue Dec 12, 2024 · 1 comment
Open

React Native for Web? #15

k2on opened this issue Dec 12, 2024 · 1 comment

Comments

@k2on
Copy link

k2on commented Dec 12, 2024

Will this work with React native for web? If not, how easy would that be for me to make an PR to add support? Thanks for your help!

@arv
Copy link

arv commented Dec 12, 2024

It will not work with RN for web. For web the default store should be used.

However, we do not expose the factory function for that in the public api.

Here is how we determine the factory to use:

export function getKVStoreProvider(
  lc: LogContext,
  kvStore: 'mem' | 'idb' | StoreProvider | undefined,
): StoreProvider {
  switch (kvStore) {
    case 'idb':
    case undefined:
      return {
        create: (name: string) => newIDBStoreWithMemFallback(lc, name),
        drop: dropIDBStoreWithMemFallback,
      };
    case 'mem':
      return {
        create: createMemStore,
        drop: (name: string) => dropMemStore(name),
      };
    default:
      return kvStore;
  }
}

We would have to export two StoreProviders. Something like:

export const idbStoreProvider: StoreProvider = {
  create: (name: string) => newIDBStoreWithMemFallback(lc, name),
  drop: dropIDBStoreWithMemFallback,
};

export const memStoreProvider: StoreProvider = {
  create: createMemStore,
  drop: (name: string) => dropMemStore(name),
};

Once that is in place the RN code could pick the right one based on its environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants