storekeep
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

storekeep

storekeep is a simple partial store saver for redux applications. storekeep allows to save some deep redux store fields between reloads of an application.

import { createStore } from "redux";
import { rootReducer } from "./reducer.js";

// you have to provide just 3 things:
// 1) a some localstorage field store data to
const LOCAL_STORAGE_FIELD = "your-app-store";
// 2) it's ok to use here a commit hash or an release version number for example
// It's required for a correct cache invalidation (in case your store structure will change)
const CACHE_TOKEN = "efwe3fwefw";
// 3) A list of fields to save
const FIELDS_TO_SAVE = [
  "todo.itemsList",
  "todo.itemsStore",
  "todo.color.accentColor",
  "todo.color.accentColor",
];

const savedStore = getPersistedState(
  rootReducer,
  LOCAL_STORAGE_FIELD,
  CACHE_TOKEN,
);

const reduxStore = persistState(
  createStore(
    rootReducer,
    savedStore,
  ),
  LOCAL_STORAGE_FIELD,
  FIELDS_TO_SAVE,
);

Readme

Keywords

none

Package Sidebar

Install

npm i storekeep

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

6.41 kB

Total Files

10

Last publish

Collaborators

  • saionaro