localforage vs redux-persist vs redux-persist-transform-filter vs redux-persist-transform-encrypt
State Management and Storage Libraries Comparison
1 Year
localforageredux-persistredux-persist-transform-filterredux-persist-transform-encryptSimilar Packages:
What's State Management and Storage Libraries?

In modern web development, managing application state and persisting it across sessions is crucial for providing a seamless user experience. These libraries serve different purposes in the context of state management and data persistence. LocalForage is a library that provides a simple API for storing data in the browser using IndexedDB, WebSQL, or localStorage, allowing for asynchronous data storage. Redux Persist is designed to persist and rehydrate Redux state, enabling applications to save their state to storage and restore it on reload. Redux Persist Transform Encrypt adds encryption capabilities to the persisted state, enhancing security. Redux Persist Transform Filter allows developers to selectively persist parts of the Redux state, optimizing storage usage and performance by filtering out unnecessary data.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
localforage4,499,53125,327-2474 years agoApache-2.0
redux-persist1,100,08013,000-5946 years agoMIT
redux-persist-transform-filter32,37019012.3 kB14-MIT
redux-persist-transform-encrypt24,3313637.31 kB0a year agoMIT
Feature Comparison: localforage vs redux-persist vs redux-persist-transform-filter vs redux-persist-transform-encrypt

Data Storage Mechanism

  • localforage:

    LocalForage abstracts the complexities of different storage mechanisms like IndexedDB, WebSQL, and localStorage, providing a unified API for developers. It supports asynchronous operations, making it suitable for applications that require non-blocking data access.

  • redux-persist:

    Redux Persist uses storage engines like localStorage or sessionStorage to persist the Redux state. It provides a simple way to save the entire Redux store or specific slices of it, ensuring that the application state is maintained across browser sessions.

  • redux-persist-transform-filter:

    Redux Persist Transform Filter allows developers to define which parts of the Redux state should be persisted. This feature is useful for optimizing storage and ensuring that only relevant data is saved, reducing storage overhead.

  • redux-persist-transform-encrypt:

    This package builds on Redux Persist by adding encryption capabilities to the persisted state. It encrypts the Redux state before saving it, ensuring that sensitive information is protected from unauthorized access.

Ease of Use

  • localforage:

    LocalForage is designed to be easy to use with a straightforward API that resembles the native localStorage API, making it accessible for developers familiar with web storage. Its promise-based approach simplifies asynchronous operations.

  • redux-persist:

    Redux Persist integrates seamlessly with Redux, requiring minimal setup to start persisting state. It provides a declarative API that allows developers to easily configure what to persist and how to rehydrate the state on application load.

  • redux-persist-transform-filter:

    Redux Persist Transform Filter is easy to implement alongside Redux Persist, allowing developers to add filtering logic with minimal changes to their existing state management setup.

  • redux-persist-transform-encrypt:

    This package extends the ease of use of Redux Persist by adding a simple configuration option for encryption, allowing developers to secure their persisted state without complicating the existing Redux setup.

Security Features

  • localforage:

    LocalForage does not inherently provide security features, as it focuses on data storage. Developers must implement their own security measures if sensitive data is stored, such as encryption before saving data.

  • redux-persist:

    Redux Persist does not include built-in security features, as it primarily focuses on state persistence. Developers should consider additional security measures for sensitive data, such as using Redux Persist Transform Encrypt.

  • redux-persist-transform-filter:

    Redux Persist Transform Filter does not directly address security but can be used in conjunction with security measures to ensure only necessary data is persisted, minimizing exposure of sensitive information.

  • redux-persist-transform-encrypt:

    This package specifically addresses security concerns by encrypting the persisted Redux state. It uses a secure encryption algorithm to protect sensitive data, making it suitable for applications that handle personal information.

Performance Optimization

  • localforage:

    LocalForage is optimized for performance, allowing for asynchronous data storage and retrieval, which prevents blocking the main thread. This is particularly important for applications that require smooth user interactions while managing data.

  • redux-persist:

    Redux Persist is designed to efficiently save and rehydrate the Redux state, but performance can vary based on the size of the state and the storage engine used. Developers can optimize performance by selectively persisting only necessary slices of state.

  • redux-persist-transform-filter:

    By filtering out unnecessary parts of the Redux state, Redux Persist Transform Filter can improve performance by reducing the amount of data that needs to be saved and rehydrated, leading to faster load times.

  • redux-persist-transform-encrypt:

    While adding encryption may introduce some performance overhead, Redux Persist Transform Encrypt is designed to minimize this impact, allowing for secure state persistence without significantly degrading application performance.

Extensibility

  • localforage:

    LocalForage is highly extensible, allowing developers to create custom storage backends if needed. Its flexibility makes it suitable for various use cases beyond standard web storage.

  • redux-persist:

    Redux Persist is designed to be extensible, allowing developers to create custom storage engines and transforms to fit their specific needs. This makes it adaptable to different application architectures and requirements.

  • redux-persist-transform-filter:

    Redux Persist Transform Filter can be combined with other transforms to create a tailored persistence solution, enabling developers to implement complex state management strategies while optimizing storage.

  • redux-persist-transform-encrypt:

    This package can be easily integrated with other Redux Persist transforms, allowing developers to create a customized persistence strategy that includes both encryption and filtering if necessary.

How to Choose: localforage vs redux-persist vs redux-persist-transform-filter vs redux-persist-transform-encrypt
  • localforage:

    Choose LocalForage if you need a simple, asynchronous storage solution that works across different storage mechanisms and is easy to integrate with various frameworks. It's ideal for applications that require offline capabilities and need to store large amounts of data efficiently.

  • redux-persist:

    Select Redux Persist if you are using Redux for state management and want to maintain the application's state across sessions. It is particularly useful for applications where user preferences or session data need to be retained after a page refresh or browser restart.

  • redux-persist-transform-filter:

    Use Redux Persist Transform Filter when you want to optimize the state persistence process by selectively saving only relevant parts of the Redux state. This is beneficial for applications with large state trees where only a subset of the state is necessary to persist.

  • redux-persist-transform-encrypt:

    Opt for Redux Persist Transform Encrypt if your application handles sensitive data that requires encryption before being stored. This package is essential for applications that prioritize data security and compliance with privacy regulations.

README for localforage

localForage

Build Status NPM version Dependency Status npm jsDelivr Hits minzipped size

localForage is a fast and simple storage library for JavaScript. localForage improves the offline experience of your web app by using asynchronous storage (IndexedDB or WebSQL) with a simple, localStorage-like API.

localForage uses localStorage in browsers with no IndexedDB or WebSQL support. See the wiki for detailed compatibility info.

To use localForage, just drop a single JavaScript file into your page:

<script src="localforage/dist/localforage.js"></script>
<script>localforage.getItem('something', myCallback);</script>

Try the live example.

Download the latest localForage from GitHub, or install with npm:

npm install localforage

Support

Lost? Need help? Try the localForage API documentation. localForage API文档也有中文版。

If you're having trouble using the library, running the tests, or want to contribute to localForage, please look through the existing issues for your problem first before creating a new one. If you still need help, feel free to file an issue.

How to use localForage

Callbacks vs Promises

Because localForage uses async storage, it has an async API. It's otherwise exactly the same as the localStorage API.

localForage has a dual API that allows you to either use Node-style callbacks or Promises. If you are unsure which one is right for you, it's recommended to use Promises.

Here's an example of the Node-style callback form:

localforage.setItem('key', 'value', function (err) {
  // if err is non-null, we got an error
  localforage.getItem('key', function (err, value) {
    // if err is non-null, we got an error. otherwise, value is the value
  });
});

And the Promise form:

localforage.setItem('key', 'value').then(function () {
  return localforage.getItem('key');
}).then(function (value) {
  // we got our value
}).catch(function (err) {
  // we got an error
});

Or, use async/await:

try {
    const value = await localforage.getItem('somekey');
    // This code runs once the value has been loaded
    // from the offline store.
    console.log(value);
} catch (err) {
    // This code runs if there were any errors.
    console.log(err);
}

For more examples, please visit the API docs.

Storing Blobs, TypedArrays, and other JS objects

You can store any type in localForage; you aren't limited to strings like in localStorage. Even if localStorage is your storage backend, localForage automatically does JSON.parse() and JSON.stringify() when getting/setting values.

localForage supports storing all native JS objects that can be serialized to JSON, as well as ArrayBuffers, Blobs, and TypedArrays. Check the API docs for a full list of types supported by localForage.

All types are supported in every storage backend, though storage limits in localStorage make storing many large Blobs impossible.

Configuration

You can set database information with the config() method. Available options are driver, name, storeName, version, size, and description.

Example:

localforage.config({
    driver      : localforage.WEBSQL, // Force WebSQL; same as using setDriver()
    name        : 'myApp',
    version     : 1.0,
    size        : 4980736, // Size of database, in bytes. WebSQL-only for now.
    storeName   : 'keyvaluepairs', // Should be alphanumeric, with underscores.
    description : 'some description'
});

Note: you must call config() before you interact with your data. This means calling config() before using getItem(), setItem(), removeItem(), clear(), key(), keys() or length().

Multiple instances

You can create multiple instances of localForage that point to different stores using createInstance. All the configuration options used by config are supported.

var store = localforage.createInstance({
  name: "nameHere"
});

var otherStore = localforage.createInstance({
  name: "otherName"
});

// Setting the key on one of these doesn't affect the other.
store.setItem("key", "value");
otherStore.setItem("key", "value2");

RequireJS

You can use localForage with RequireJS:

define(['localforage'], function(localforage) {
    // As a callback:
    localforage.setItem('mykey', 'myvalue', console.log);

    // With a Promise:
    localforage.setItem('mykey', 'myvalue').then(console.log);
});

TypeScript

If you have the allowSyntheticDefaultImports compiler option set to true in your tsconfig.json (supported in TypeScript v1.8+), you should use:

import localForage from "localforage";

Otherwise you should use one of the following:

import * as localForage from "localforage";
// or, in case that the typescript version that you are using
// doesn't support ES6 style imports for UMD modules like localForage
import localForage = require("localforage");

Framework Support

If you use a framework listed, there's a localForage storage driver for the models in your framework so you can store data offline with localForage. We have drivers for the following frameworks:

If you have a driver you'd like listed, please open an issue to have it added to this list.

Custom Drivers

You can create your own driver if you want; see the defineDriver API docs.

There is a list of custom drivers on the wiki.

Working on localForage

You'll need node/npm and bower.

To work on localForage, you should start by forking it and installing its dependencies. Replace USERNAME with your GitHub username and run the following:

# Install bower globally if you don't have it:
npm install -g bower

# Replace USERNAME with your GitHub username:
git clone git@github.com:USERNAME/localForage.git
cd localForage
npm install
bower install

Omitting the bower dependencies will cause the tests to fail!

Running Tests

You need PhantomJS installed to run local tests. Run npm test (or, directly: grunt test). Your code must also pass the linter.

localForage is designed to run in the browser, so the tests explicitly require a browser environment. Local tests are run on a headless WebKit (using PhantomJS).

When you submit a pull request, tests will be run against all browsers that localForage supports on Travis CI using Sauce Labs.

Library Size

As of version 1.7.3 the payload added to your app is rather small. Served using gzip compression, localForage will add less than 10k to your total bundle size:

minified
`~29kB`
gzipped
`~8.8kB`
brotli'd
`~7.8kB`

License

This program is free software; it is distributed under an Apache License.


Copyright (c) 2013-2016 Mozilla (Contributors).