Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alt-localstore

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alt-localstore

save and restore alt store state to localStorage, listens to changes

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Alt LocalStore

This is a module for automatically saving and restoring store state from localStorage for react applications using alt and immutable.

Setup

First, make sure you make the setState() method public in the state constructor like so:

class MyStore {

  constructor() {

    this.exportPublicMethods({
      setState: this.setState
    });

  }

}

Without this, the localstore won't be able to restore the store state from localStorage.

Usage

import LocalStore from 'alt-localstore';
import MyStore from './MyStore';

let myStore    = alt.createStore(MyStore);
let localCache = new LocalStore(myStore);

localCache.restore();

constructor(store[, localStorageKey])

Constructor takes in an alt store instance and an optional key to be used for localStorage which defaults to the store displayName.

save([state])

Save the store state to localStorage. Automatically called on store state changes.
Takes in optional state param to save instead of the store state.

restore()

Restore the localStorage saved data to the state store. Defaults to {}.

listen()

Listen to store state changes and automatically persist the new state to localStorage. Automatically called in the constructor.

unlisten()

Stop listening to store state changes.

Source Code

Source code was originally written in es6. Default import retrieves the babel transpiled es5 version. To import the es6 version of the module, use import LocalStore from 'alt-localstore/index.es6'

Keywords

FAQs

Package last updated on 01 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc