npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mobx-localforage-store

v0.8.0

Published

MobX + localForage = a clean reactive data-persistent store

Readme

MobX-localForage-Store

MobX + localForage = a clean reactive data-persistent store.

Install

npm install mobx-localforage-store

Usage

Example

import Store from 'mobx-localforage-store'

const reactiveStore = new Store({
  counter: 1
});

const persistenStore = new Store('namespace', {
  user: {some: 'data worth persisting'}
});

@Store.observe
class ViewComponent {
  render () {
    return "It updates: " + store.counter +  persistenStore.user
  }
  async save(){
    await persistenStore.setItem('user', {changed: 'data'})
  }
}

setInterval(() => {
  reactiveStore.counter++;
});

While both reactiveStore and persistenStore are reactive (both will trigger render() on change), persistenStore stores data using localForage.

setItem makes any new data (other than the one initialized) reactive, and optionally (if persistent storage is configured) stores it in localForage

API

The API is much like localForage but it makes the properties observable.

methods

constructor([name=string], [data=array|object], [opts=object])
  • name - Required for localForage. Without it it's just MobX reactive store, but still uses localForage-like API (setItem) to make properties observable (unless Proxy support is available)

  • data - Data to initialize with. Can also be just an array of keys.

  • opts

    • opts.useProxy (default:true if available) Uses ES6 Proxy to automatically make properties set mobx-reactive.
    • opts.debounce (default:false) Uses debounce-promise to delay setItem. Although directly changing properties triggers mobx (which itself is expensive) and it bypasses the debounced setItem.
Method similar to localForage:
setItem(key=string, data=any) => Promise

Sets a property, makes it mobx-observable if not already, and if localForage is configured returns localForage.setItem(...) (which is a promise)

getItem(key=string, data=any) => Promise

Gets a property from localForage and runs setItem. Throws if localForage was not configured.

removeItem(key=string) => Promise

Removes a property, and if localForage was configured returns localForage.removeItem(...)

clear() => Promise

Runs removeItem on all keys found.

Additional methods:
restore([keys=array]) => Promise

Gets all keys (either passed or Object.keys(this)) from localForage, runs setItem on them. Throws if localForage was not configured. Returns a promise that resolves to restored key-values object.

setState(data=object) => Promise

Takes an object and runs setItem on every key-value pair. It's like React's this.setState.

Method related to MobX:
toJS() => object

Returns mobx.toJS(this)

intercept()

Calls mobx.intercept() with target as this, so just provide it with rest of the arguments (propertyName?, listener, invokeImmediately?)

observe()

Calls mobx.observe() with target as this, so just provide it with rest of the arguments (propertyName?, listener, invokeImmediately?)

(this is different from the @static method Store.observe)

Static methods
@static observe()

Shortcut to mobxObserver.observer

(this is different from the @instance method observe)

@static observeStateless()

Shortcut to mobxObserver.makeObserver

(this is different from the @instance method observe)

@static autorun()

Shortcut to mobx.autorun

@static config()

Shortcut to localForage.config

Properties

store

The underlying localForage store created with localForage.createInstance({ name }) (only if name was passed to constructor)

ready

Returns a promise that resolves when:

  • the constructor was called with data as an array of keys, this promise resolves when all the keys were loaded from localForage

  • the constructor was called with data as an object, this promise resolves when setItem has been called for all the keys