aveq-research/localforage-asyncstorage-driver

No available storage method found

mayur-bhandari opened this issue · 5 comments

Hello,

I am trying to use this driver for a react-native sdk. The SDK is in typescript. I have successfully implemented local forage for web sdk and now I am trying to implement this driver to be able to use local forage for the react-native sdk. I am sharing the code snippet below and the output I get when I integrate the SDK in a react-native android app.

Code:

this.keyStore = localforage.createInstance({
    name: format(LOCAL_STORE.STORE_STRING, CometChat.getAppId(), LOCAL_STORE.KEYS_STORE)
});
const driver = driverWithoutSerialization();
this.keyStore.defineDriver(driver).then(
    () => {
        this.keyStore.setDriver(driver._driver).then(
            () => {
                driver._support().then(
                    support => {
                        console.log('_support', support);
                        console.log('keyStore', this.keyStore);
                        this.keyStore.keys().then(
                            keys => {
                                console.log('keys', keys);
                                this.keyStore.setItem('deviceId1', 'it-should-work').then(
                                    setItem => {
                                        console.log('setItem', setItem);
                                        this.keyStore.getItem('deviceId1').then(
                                            getItem => {
                                                console.log('getItem', getItem);
                                            }, err => {
                                                console.log('error in getItem', err);
                                            }
                                        );
                                    }, err => {
                                        console.log('error in setItem', err);
                                    }
                                );
                            }, err => {
                                console.log('error in keys', err);
                            }
                        );
                    }, err => {
                        console.log('error in support', err);
                    }
                );
            }, err => {
                console.log('error in setDriver', err);
            }
        )
    }, err => {
        console.log('error in defineDriver', err);
    }
);

Output:

Screen Shot 2020-07-16 at 1 14 07 PM

Hi @mayur-bhandari!

Thanks for the issue. Although the "_support" tag returns true. Just to be sure: Are you able to access the ReactNative AsyncStorage in general (without LocalForage)?

Try e.g. this code-snippet in your application:

import AsyncStorage from '@react-native-community/async-storage';

AsyncStorage.setItem('test', 'it-works').then(() => {
  AsyncStorage.getItem('test').then((result) => {
   console.log(result);
  });
});

If this works, my next question is, if general getting and setting of items still works in your code, without using the "keys()"-method. Try therefore this snippet please:

import localforage from 'localforage';
import { driverWithoutSerialization } from '@aveq-research/localforage-asyncstorage-driver';

const driver = driverWithoutSerialization();
localforage.defineDriver(driver).then(() => {
  localforage.setDriver(driver._driver).then(() => {
    localforage.setItem('test', 'it-still-works').then(() => {
      localforage.getItem('test').then((result) => {
        console.log(result);
      });
    });
  });
});

Could you please tell me, if they are running? I think the problem shouldn't be typescript, since we are running the code in our TS applications, too.

Hey @mayur-bhandari!

While investigating further bug reasons I found another bug in the keys method, which I solved in this turn and made a new release to v1.1.1. Could you please make an update and check if your error still persists?

Best

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hey @fohletex ,

Since I needed a solution faster I started to use AsyncStorage for react-native instead of local forage.

Dear @mayur-bhandari - That's ok. If you only aim to develop ReactApps which shouldn't be transfered to other environments, the native AsyncStorage is mostly sufficient. If you require localforage in the future, I hope you like to come back. It seems as if your issue from July 16 is already solved.