Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edy/redux-persist-transform-filter
Filter transformator for redux-persist
https://github.com/edy/redux-persist-transform-filter
filter redux transform
Last synced: 3 days ago
JSON representation
Filter transformator for redux-persist
- Host: GitHub
- URL: https://github.com/edy/redux-persist-transform-filter
- Owner: edy
- License: mit
- Created: 2016-08-16T19:30:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T14:58:14.000Z (over 1 year ago)
- Last Synced: 2024-12-13T17:25:18.968Z (10 days ago)
- Topics: filter, redux, transform
- Language: JavaScript
- Size: 806 KB
- Stars: 190
- Watchers: 6
- Forks: 21
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-persist-transform-filter
[![npm](https://img.shields.io/npm/v/redux-persist-transform-filter.svg?maxAge=2592000&style=flat-square)](https://www.npmjs.com/package/redux-persist-transform-filter)
[![Build Status](https://travis-ci.org/edy/redux-persist-transform-filter.svg?branch=master)](https://travis-ci.org/edy/redux-persist-transform-filter)Filter transformator for redux-persist
## Installation
```
npm install redux-persist-transform-filter
```## Usage
```js
import { createFilter, createBlacklistFilter } from 'redux-persist-transform-filter';// this works too:
import createFilter, { createBlacklistFilter } from 'redux-persist-transform-filter';// you want to store only a subset of your state of reducer one
const saveSubsetFilter = createFilter(
'myReducerOne',
['keyYouWantToSave1', 'keyYouWantToSave2']
);// you want to remove some keys before you save
const saveSubsetBlacklistFilter = createBlacklistFilter(
'myReducerTwo',
['keyYouDontWantToSave1', 'keyYouDontWantToSave2']
);// you want to load only a subset of your state of reducer three
const loadSubsetFilter = createFilter(
'myReducerThree',
null,
['keyYouWantToLoad1', 'keyYouWantToLoad2']
);// saving a subset and loading a different subset is possible
// but doesn't make much sense because you'd load an empty state
const saveAndloadSubsetFilter = createFilter(
'myReducerFour',
['one', 'two']
['three', 'four']
);const predicateFilter = persistFilter(
'form',
[
{ path: 'one', filterFunction: (item: any): boolean => item.mustBeStored },
{ path: 'two', filterFunction: (item: any): boolean => item.mustBeStored },
],
'whitelist'
)const normalPathFilter = persistFilter(
'form',
['one', 'two'],
'whitelist'
)persistStore(store, {
transforms: [
saveSubsetFilter,
saveSubsetBlacklistFilter,
loadSubsetFilter,
saveAndloadSubsetFilter,
]
});
```## Example project
```sh
git clone https://github.com/edy/redux-persist-transform-filter-example.git
cd redux-persist-transform-filter-example
npm install
npm start
```