🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@r/redux-state-archiver

Package Overview
Dependencies
Maintainers
7
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@r/redux-state-archiver

A collection of React components for serializing your redux state

latest
Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
1
-97.22%
Maintainers
7
Weekly downloads
 
Created
Source

@r/redux-state-archiver

makeStateArchiver returns a React Component to be used in a subtree of from react-redux. It will listen to your redux state and archive that data when it changes.

The arguments to makeStateArchiver are simliar to createSelector, pass in an array of selectors that extract the data you from state you wish to serialize.

const themeSelector = (state) => state.theme;

After your selectors, pass in a 'combiner' to merge the data from your selectors into an object that will represent the overall state of data you wish to serialize;

const combiner = (theme) => ({ theme });

Finally pass in a state archiver, a function that takes an object, and persists it in some manner. You probably will never pass this, as most apps can use the helper functions makeCookieArchiver or makeLocalStorageArchiver. These functions try to match the signature of connect from 'react-redux', so you pass your selectors as arguments without wrapping them in an array.

Note: Your archiver should be able to deal with persisting the diff of what's output from your combiner.

Full example:

import React from 'react';
import { Provider } from 'react-redux';
import { makeCookieArchiver } from '@r/redux-state-archiver';
import { UrlSync } from '@r/platform/components';
import App from './src/App';

const themeSelector = (state) => state.theme;
const compactSelector = (state) => state.compact;
const combiner = (theme, compact) => ({ theme, compact });
const CookieSync = makeCookieArchiver(
  themeSelector,
  compactSelector,
  combiner,
);

const renderApp = (store) => (
  <Provider store={ store }>
    <App />
    <UrlSync />
    <CookieSync />
  </Provider>
);

Keywords

es6

FAQs

Package last updated on 11 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts