All Projects → react-stack → redux-storage

react-stack / redux-storage

Licence: MIT license
Persistence layer for redux with flexible backends

Projects that are alternatives of or similar to redux-storage

Redux Persist
persist and rehydrate a redux store
Stars: ✭ 11,738 (+5284.4%)
Mutual labels:  storage, redux-middleware, persistor
awesome-storage
A curated list of storage open source tools. Backups, redundancy, sharing, distribution, encryption, etc.
Stars: ✭ 324 (+48.62%)
Mutual labels:  storage
redux-airbrake
Redux middleware for Airbrake error logging
Stars: ✭ 20 (-90.83%)
Mutual labels:  redux-middleware
synology-csi
Container Storage Interface (CSI) for Synology
Stars: ✭ 136 (-37.61%)
Mutual labels:  storage
bitcrust
Bitcoin software suite
Stars: ✭ 61 (-72.02%)
Mutual labels:  storage
Pomegranate
🌳 A tiny skiplist based log-structured merge-tree written in Rust.
Stars: ✭ 20 (-90.83%)
Mutual labels:  storage
StarWarsSearch-MVI
Star wars sample android project showcasing the use of View components for rendering UI in Fragments and Activities. Uses Android Jetpack, clean architecture with MVI (Uni-directional data flow), dagger hilt, and kotlin coroutines with StateFlow
Stars: ✭ 189 (-13.3%)
Mutual labels:  redux-store
ReduxSimple
Simple Stupid Redux Store using Reactive Extensions
Stars: ✭ 119 (-45.41%)
Mutual labels:  redux-store
birthday.py
🎉 A simple discord bot in discord.py that helps you understand the usage of SQL databases
Stars: ✭ 30 (-86.24%)
Mutual labels:  storage
redux-bluetooth
Redux middleware to dispatch actions via bluetooth to a peripheral store
Stars: ✭ 17 (-92.2%)
Mutual labels:  redux-middleware
ng2-storage
A local and session storage wrapper for angular 2.
Stars: ✭ 14 (-93.58%)
Mutual labels:  storage
drive-desktop
internxt.com/drive
Stars: ✭ 102 (-53.21%)
Mutual labels:  storage
MusicX
MusicX is a music player 🎵 android app built using Kotlin and Jetpack Compose. It follows M.A.D. practices and hence is a good learning resource for beginners
Stars: ✭ 85 (-61.01%)
Mutual labels:  storage
apollo-cache-instorage
Apollo Cache implementation that facilitates locally storing resources
Stars: ✭ 98 (-55.05%)
Mutual labels:  storage
BlobHelper
BlobHelper is a common, consistent storage interface for Microsoft Azure, Amazon S3, Komodo, Kvpbase, and local filesystem written in C#.
Stars: ✭ 23 (-89.45%)
Mutual labels:  storage
redux-state-history
Redux store enhancers for tracking and visualizing state changes
Stars: ✭ 92 (-57.8%)
Mutual labels:  redux-store
estuary
A custom IPFS/Filecoin node that makes it easy to pin IPFS content and make Filecoin deals.
Stars: ✭ 195 (-10.55%)
Mutual labels:  storage
storage
A library to use Web Storage API with Observables
Stars: ✭ 43 (-80.28%)
Mutual labels:  storage
linode-blockstorage-csi-driver
Container Storage Interface (CSI) Driver for Linode Block Storage
Stars: ✭ 50 (-77.06%)
Mutual labels:  storage
cstor-operators
Collection of OpenEBS cStor Data Engine Operators
Stars: ✭ 77 (-64.68%)
Mutual labels:  storage

redux-storage

build dependencies devDependencies

license npm version npm downloads

Save and load the Redux state with ease.

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 storeageAwareReducer(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 ]);

If you want to skip dispatching a redux action everytime something gets saved, just specify it to the option object, which is the fourth argument.

import { createMiddleware } from 'redux-storage'

import { SHOULD_SAVE } from './constants';

const middleware = createMiddleware(engine, [], [], { disableDispatchSaveAction: true });

A fork of redux-storage

The original author of the package redux-storage has decided to deprecate the project and no longer maintained. The package will now be maintained here.

Thank you michaelcontento for a great library!

License

The MIT License (MIT)

Copyright (c) 2016- Gunjan Soni <[email protected]>
Copyright (c) 2015-2016 Michael Contento <[email protected]>

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].