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 Introduction

localforage-asyncstorage-driver

npm version

This Library contains a driver which enables to use localforage for React-Native's AsyncStorage.

Peer Dependencies

Please note! With the switch to v3.0.0 @react-native-async-storage/async-storage became a peer dependency!!

Setup

Simply install the driver via NPM:

npm i --save @aveq-research/localforage-asyncstorage-driver

If not done yet, make sure to have the appropriate peer dependencies (react resp. react-native) to be installed.

Usage

It delivers three different methods to create an appropriate driver:

  • driverWithoutSerialization(): Create a common AsyncStorage driver which does not serialize any data automatically; you need to integrate your own serialization!
  • driverWithSerialization(serializer): Creates an AsyncStorage driver with the given serializer; A valid serializer needs to contain a serialize and deserialize method
  • driverWithDefaultSerialization(): Will use the default serialization from localforage

Working Code Example:

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

const driver = driverWithoutSerialization();
await localforage.defineDriver(driver);
await localforage.setDriver(driver._driver); // i.e. "rnAsyncStorageWrapper"

Alternatively with instance usage:

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

const driver = driverWithoutSerialization();
const instance = localforage.createInstance({ driver });

After that you may use localforage as you know it already. For further questions concerning the localforage API, lookup https://github.com/localForage/localForage

License

This driver is distributed under MIT License (see LICENSE) and maintained by the wonderful AVEQ team.

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.