@sil/storage
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

Storage

Save your state in localstorage and automatically retrieve on initialisation.

Installation

npm install @sil/storage

Usage

Example in Vue, initialize a state and make sure the state taken from local storage when available. The watchState makes sure your state will automatically be saved whenever changes are made.

import { reactive } from "vue";
import { retrieveState, watchState } from "@sil/storage";

const state = reactive(
  retrieveState(
    {
      count: 0,
    },
    "MY_STATE"
  )
);

watchState(state, "MY_STATE");

Options

You can add the options to your retrieveState and watchState in order to change defaults.

Option Default Description
verbose false Show logging in console whenever an action happens

example:

const options = {
  verbose: true,
};

const state = reactive(
  retrieveState(
    {
      count: 0,
    },
    "MY_STATE",
    options
  )
);

watchState(state, "MY_STATE", options);

Package Sidebar

Install

npm i @sil/storage

Weekly Downloads

5

Version

0.0.7

License

MIT

Unpacked Size

9.58 kB

Total Files

5

Last publish

Collaborators

  • hacobvandipyan
  • silvandiepen