3.0.2 • Published 7 years ago

choo-persist v3.0.2

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

choo-persist stability

npm version build status downloads js-standard-style

Persist choo state to localStorage. localStorage is supported by all major browsers.

Usage

var persist = require('choo-persist')
var choo = require('choo')

var app = choo()
app.use(persist())

API

instance = persist([opts])

Load the app state from localStorage and set up listeners to write the state back on every event. Can take an optional argument of options:

  • opts.name: default 'choo-persist'; the localStorage key.
  • opts.filter(state): modify the state that's about to be saved. Useful for removing values that cannot be serialized to JSON.
var xtend = require('xtend')
var opts = {
  filter: function (state) {
    state = xtend(state) // clone the object
    delete state.sadArrayFilledWithFunctions
    return state
  }
}

Installation

$ npm install choo-persist

Should I use this while developing.

No; state is persisted between page reloads which might put your page in very odd states, with a very annoying way to clear. Consider using hot reloading for development instead.

How / when should I invalidate the database cache?

Ah, this is where good ol' data persistance comes into play - there's loads of approaches on this, but yeah you should def find a way to migrate data between incompatible models. Perhaps some day we'll have a good chapter on this in the choo handbook. Until then: have fun I guess?

License

MIT

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago