Giter Site home page Giter Site logo

aveq-research / localforage-asyncstorage-driver Goto Github PK

View Code? Open in Web Editor NEW
21.0 5.0 0.0 857 KB

Driver which enables you to use localforage for React-Native's AsyncStorage API

License: MIT License

JavaScript 100.00%
localforage localforage-driver react-native asyncstorage asyncstorage-wrapper react-native-storage

localforage-asyncstorage-driver's People

Contributors

dependabot[bot] avatar fohletex avatar kuasha420 avatar slhck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

localforage-asyncstorage-driver's Issues

support createInstance

Hi there!

Thanks a lot for this package - its really nifty. In fact I am using it as a dependency in a cache wrapper im working on :). I haven't tested this in live code, but writing jest tests for my package, I noticed something peculiar-

const AsyncStorageDriver = driverWithDefaultSerialization()
await localforage.defineDriver(AsyncStorageDriver)
await localforage.setDriver(AsyncStorageDriver._driver)
//@ts-ignore
console.log(localforage._driver) // "rnAsyncStorageWrapper-withDefaultSerializer"

const instance = localforage.createInstance()

//@ts-ignore
console.log(localforage._config._driver) // "localStorageWrapper"

Does this package support instances?

Not able to create instance for the store

I am not able to add the instance name for the store for react native. It throws an error. Error: No available storage method found. I am trying to keep separate instance so we do not clear the entire instance the entire for that instance db.
Versions below

{  
"expo": "~48.0.5",
"react-native": "0.71.3",
"@aveq-research/localforage-asyncstorage-driver": "^3.0.1",
@react-native-async-storage/async-storage": "^1.17.11",
"localforage": "^1.10.0"
}

image

No available storage method found

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.