All Projects → michaelcontento → Redux Storage

michaelcontento / Redux Storage

Licence: mit
Persistence layer for redux with flexible backends

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Redux Storage

Unqlite
An Embedded NoSQL, Transactional Database Engine
Stars: ✭ 1,583 (+132.45%)
Mutual labels:  database, storage
Filebase
A Simple but Powerful Flat File Database Storage.
Stars: ✭ 235 (-65.49%)
Mutual labels:  database, storage
Irmin
Built-in Snapshotting - backup and restore Storage Agnostic - you can use Irmin on top of your own storage layer Custom Datatypes - (de)serialization for custom data types, derivable via ppx_irmin Highly Portable - runs anywhere from Linux to web browsers and Xen unikernels Git Compatibility - irmin-git uses an on-disk format that can be inspected and modified using Git Dynamic Behavior - allows the users to define custom merge functions, use in-memory transactions (to keep track of reads as well as writes) and to define event-driven workflows using a notification mechanism
Stars: ✭ 1,524 (+123.79%)
Mutual labels:  database, storage
React Native Firebase
🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
Stars: ✭ 9,674 (+1320.56%)
Mutual labels:  database, storage
Rustbreak
A simple, fast and easy to use self-contained single file storage for Rust
Stars: ✭ 315 (-53.74%)
Mutual labels:  database, storage
Pufferdb
🐡 An Android & JVM key-value storage powered by Protobuf and Coroutines
Stars: ✭ 91 (-86.64%)
Mutual labels:  database, storage
Tera
An Internet-Scale Database.
Stars: ✭ 1,846 (+171.07%)
Mutual labels:  database, storage
Hexa
Hexa: The ultimate companion for Azure. Setup and deploy in seconds
Stars: ✭ 56 (-91.78%)
Mutual labels:  database, storage
React Native Mmkv Storage
An Efficient(0.0002s read/write), small & encrypted mobile key-value storage framework for React Native
Stars: ✭ 273 (-59.91%)
Mutual labels:  database, storage
Immortaldb
🔩 A relentless key-value store for the browser.
Stars: ✭ 2,962 (+334.95%)
Mutual labels:  database, storage
Vault
Easy persistence of Contentful data for Android over SQLite.
Stars: ✭ 80 (-88.25%)
Mutual labels:  database, storage
Sleekdb
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Stars: ✭ 450 (-33.92%)
Mutual labels:  database, storage
Pumpkindb
Immutable Ordered Key-Value Database Engine
Stars: ✭ 1,219 (+79%)
Mutual labels:  database, storage
Bojack
🐴 The unreliable key-value store
Stars: ✭ 101 (-85.17%)
Mutual labels:  database, storage
Oblecto
Oblecto is a media server, which streams media you already own, and is designed to be at the heart of your entertainment experience. It runs on your home server to index and analyze your media such as Movies and TV Shows and presents them in an interface tailored for your media consupmtion needs.
Stars: ✭ 67 (-90.16%)
Mutual labels:  database, storage
Combinefirebase
Combine wrapper on Google's iOS Firebase library.
Stars: ✭ 126 (-81.5%)
Mutual labels:  database, storage
Dexie.js
A Minimalistic Wrapper for IndexedDB
Stars: ✭ 7,337 (+977.39%)
Mutual labels:  database, storage
Aresdb
A GPU-powered real-time analytics storage and query engine.
Stars: ✭ 2,814 (+313.22%)
Mutual labels:  database, storage
Firebase Instagram
📸 Instagram clone with Firebase Cloud Firestore, Expo, and React Native 😁😍
Stars: ✭ 389 (-42.88%)
Mutual labels:  database, storage
Rxfirebase
Rxjava 2.0 wrapper on Google's Android Firebase library.
Stars: ✭ 509 (-25.26%)
Mutual labels:  database, storage

redux-storage

build dependencies devDependencies

license npm version npm downloads Code Climate

Save and load the Redux state with ease.

Moved to the react-stack organisation

My focus has left the node / react ecosystem and this module has got a new home over at react-stack!

Features

  • Flexible storage engines
  • Flexible state merger functions
  • Storage engines can be async
  • Load and save actions that can be observed
    • SAVE: { type: 'REDUX_STORAGE_SAVE', payload: /* state tree */ }
    • LOAD: { type: 'REDUX_STORAGE_LOAD', payload: /* state tree */ }
  • Various engine decorators
  • Black- and whitelist actions from issuing a save operation

Installation

npm install --save redux-storage

And you need to install at least one redux-storage-engine, as redux-storage is only the "management core".

Usage

import * as storage from 'redux-storage'

// Import redux and all your reducers as usual
import { createStore, applyMiddleware, combineReducers } from 'redux';
import * as reducers from './reducers';

// We need to wrap the base reducer, as this is the place where the loaded
// state will be injected.
//
// Note: The reducer does nothing special! It just listens for the LOAD
//       action and merge in the provided state :)
// Note: A custom merger function can be passed as second argument
const reducer = storage.reducer(combineReducers(reducers));

// Now it's time to decide which storage engine should be used
//
// Note: The arguments to `createEngine` are different for every engine!
import createEngine from 'redux-storage-engine-localstorage';
const engine = createEngine('my-save-key');

// And with the engine we can create our middleware function. The middleware
// is responsible for calling `engine.save` with the current state afer
// every dispatched action.
//
// Note: You can provide a list of action types as second argument, those
//       actions will be filtered and WON'T trigger calls to `engine.save`!
const middleware = storage.createMiddleware(engine);

// As everything is prepared, we can go ahead and combine all parts as usual
const createStoreWithMiddleware = applyMiddleware(middleware)(createStore);
const store = createStoreWithMiddleware(reducer);

// At this stage the whole system is in place and every action will trigger
// a save operation.
//
// BUT (!) an existing old state HAS NOT been restored yet! It's up to you to
// decide when this should happen. Most of the times you can/should do this
// right after the store object has been created.

// To load the previous state we create a loader function with our prepared
// engine. The result is a function that can be used on any store object you
// have at hand :)
const load = storage.createLoader(engine);
load(store);

// Notice that our load function will return a promise that can also be used
// to respond to the restore event.
load(store)
    .then((newState) => console.log('Loaded state:', newState))
    .catch(() => console.log('Failed to load previous state'));

Details

Engines, Decorators & Mergers

They all are published as own packages on npm. But as a convention all engines share the keyword redux-storage-engine, decorators can be found with redux-storage-decorator and mergers with redux-storage-merger. So it's pretty trivial to find all the additions to redux-storage you need 😄

Actions

redux-storage will trigger actions after every load or save operation from the underlying engine.

You can use this, for example, to display a loading screen until the old state has been restored like this:

import { LOAD, SAVE } from 'redux-storage';

function storageAwareReducer(state = { loaded: false }, action) {
    switch (action.type) {
        case LOAD:
            return { ...state, loaded: true };

        case SAVE:
            console.log('Something has changed and written to disk!');

        default:
            return state;
    }
}

Middleware

If you pass an array of action types as second argument to createMiddleware, those will be added to a internal blacklist and won't trigger calls to engine.save.

import { createMiddleware } from 'redux-storage'

import { APP_START } from './constants';

const middleware = createMiddleware(engine, [ APP_START ]);

If you want to whitelist all actions that are allowed to issue a engine.save, just specify them as third argument.

import { createMiddleware } from 'redux-storage'

import { SHOULD_SAVE } from './constants';

const middleware = createMiddleware(engine, [], [ SHOULD_SAVE ]);

License

The MIT License (MIT)

Copyright (c) 2015 Michael Contento

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].