1.1.1 • Published 7 years ago

hyperapp-persist-state v1.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

HyperApp Persist State

Reuse the previous app's state for faster reload

This library is a High Order App which encapsulates your 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

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