Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucasmrdt/nedux-persist
🔒 Persist your nedux store
https://github.com/lucasmrdt/nedux-persist
localstorage nedux-middleware persistent-storage persistor typescript
Last synced: about 1 month ago
JSON representation
🔒 Persist your nedux store
- Host: GitHub
- URL: https://github.com/lucasmrdt/nedux-persist
- Owner: lucasmrdt
- License: mit
- Created: 2019-12-06T20:21:24.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T02:28:37.000Z (almost 2 years ago)
- Last Synced: 2024-04-26T04:21:36.003Z (8 months ago)
- Topics: localstorage, nedux-middleware, persistent-storage, persistor, typescript
- Language: JavaScript
- Homepage:
- Size: 231 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nedux-persist - persist your nedux store
![typescript](https://img.shields.io/badge/-typescript-blueviolet) [![version](https://img.shields.io/badge/version-beta-blue)](https://www.npmjs.com/package/nedux-persist) [![size](https://img.shields.io/bundlephobia/minzip/nedux-persist?color=green&label=size)](https://www.npmjs.com/package/nedux-persist)
> The official [middleware](https://github.com/lucasmrdt/nedux#%EF%B8%8F-middlewares) persistor for [nedux](https://github.com/lucasmrdt/nedux). Performant and flexible.
## 📦 Installation
```bash
npm install nedux-persist --save
```## 💻 Usage with examples
| Name | Codesandbox |
| :-----------------: | :----------------------------------------------------------------------------------------: |
| 🔒 Persisting Token | [here](https://codesandbox.io/s/new-feather-777tm?fontsize=14&hidenavigation=1&theme=dark) | [here](https://codesandbox.io/s/nedux-todos-nm8j0?fontsize=14&hidenavigation=1&theme=dark) |## 📜 Documentation
### `Import`
```javascript
// ES6
import { persistKeys } from 'nedux-persist';// ES5
var persistKeys = require('nedux-persist').persistKeys;
```### `persistKeys(keys, [localStorage])`
Create a middleware that may your `keys` persisted.
| argument | required | type | description |
| :------------: | :------: | :-----------------: | :-------------------------------- |
| `keys` | ✅ | `string[]` | The keys that you want to persist |
| `localStorage` | ❌ | [Storage](#storage) | The keys that you want to persist |### Storage
| argument | required | type | description |
| :-------: | :------: | :------------------------------------: | :------------------------- |
| `getItem` | ✅ | `(key: string) => string` | Get the value from Storage |
| `setItem` | ✅ | `(key: string, value: string) => void` | Set the value into Storage |## 🎛 Basic Usage
```typescript
import { createStore } from 'nedux';
import { persistKeys } from 'nedux-persist';type Store = {
token: string;
useless: number;
};const store = createStore(
{ token: '', useless: 0 },
[persistKeys(['token'])],
);store.subscribe('token', { next: token => console.log(`token: ${token}`) });
```## 🙋🏼 Contributions
All [Pull Requests](https://github.com/lucasmrdt/nedux-persist/compare?expand=1), [Issues](https://github.com/lucasmrdt/nedux-persist/issues) and [Discussions](https://github.com/lucasmrdt/nedux-persist/issues) are welcomed !