Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        

# HyperApp Persist State
> Reuse the previous app's state for faster reload

This 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