Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abhisaha1/hyperapp-persist-state
A tiny HOA to persist the state of HyperApp and load it in next use
https://github.com/abhisaha1/hyperapp-persist-state
Last synced: 4 days ago
JSON representation
A tiny HOA to persist the state of HyperApp and load it in next use
- Host: GitHub
- URL: https://github.com/abhisaha1/hyperapp-persist-state
- Owner: abhisaha1
- Created: 2017-11-07T22:28:27.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-08T08:56:30.000Z (about 7 years ago)
- Last Synced: 2024-12-10T05:53:01.522Z (19 days ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HyperApp Persist State
> Reuse the previous app's state for faster reloadThis library is a High Order App which encapsulates your [Hyperapp](https://github.com/hyperapp/hyperapp) and saves your state for the next page load increasing performance and also giving (partial) offline capability.
## Install
```
npm i hyperapp-persist-state --save
```
## Usage
```js
import { app } from "hyperapp";
import persist from "hyperapp-persist-state";const options = {
state,
actions,
view
};
// Wrap the options inside persist
const appActions = app(
persist(options, {
storage: "localStorage",
clearPast: true,
version: 1
})
);
appActions.__initPersist();
```## Options
##### `storage - {string} (optional) | Default: localStorage`Uses localStorage to save the state
##### `version - {int} (optional) | Default: 1`
When there are breaking changes in the state, increament the version number. This will remove the old state and initialize the storage with the new state.
##### `clearPast - {bool} (optional) | Default: true`
If this is false, it will keep the old states in the storage.
The states are stored in the format `app-state-v-{version}`.
## Deactivate
##### `actions.__removePersist()`
This will clear the data from the store and deactivate persistance.## Todo
Add options for IndexedDB