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

vuex-persistedstate

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuex-persistedstate - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

src/plugin.js

14

dist/vuex-persistedstate.js
/**
* vuex-persistedstate v0.1.0
* vuex-persistedstate v0.3.0
*

@@ -12,3 +12,3 @@ * (c) 2016 Robin van der Vleuten <robin@webstronauts.co>

typeof define === 'function' && define.amd ? define(['lodash.merge', 'object-path'], factory) :
(global.VuexPersistedstate = factory(global.merge,global.objectPath));
(global.createPersistedState = factory(global.merge,global.objectPath));
}(this, (function (merge,objectPath) { 'use strict';

@@ -23,13 +23,17 @@

var paths = ref.paths; if ( paths === void 0 ) paths = [];
var getState = ref.getState; if ( getState === void 0 ) getState = function (key) { return JSON.parse(localStorage.getItem(key)); };
var setState = ref.setState; if ( setState === void 0 ) setState = function (key, state) { return localStorage.setItem(key, JSON.stringify(state)); };
return function (store) {
store.replaceState(
merge({}, store.state, JSON.parse(localStorage.getItem(key)))
merge({}, store.state, getState(key))
)
store.subscribe(function (mutation, state) {
localStorage.setItem(key, JSON.stringify(paths.reduce(function (substate, path) {
var persistedState = paths.length === 0 ? state : paths.reduce(function (substate, path) {
objectPath.set(substate, path, objectPath.get(state, path))
return substate
}, {})))
}, {})
setState(key, persistedState)
})

@@ -36,0 +40,0 @@ }

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("lodash.merge"),require("object-path")):"function"==typeof define&&define.amd?define(["lodash.merge","object-path"],t):e.VuexPersistedstate=t(e.merge,e.objectPath)}(this,function(e,t){"use strict";function o(o){void 0===o&&(o={});var r=o.key;void 0===r&&(r="vuex");var n=o.paths;return void 0===n&&(n=[]),function(o){o.replaceState(e({},o.state,JSON.parse(localStorage.getItem(r)))),o.subscribe(function(e,o){localStorage.setItem(r,JSON.stringify(n.reduce(function(e,r){return t.set(e,r,t.get(o,r)),e},{})))})}}return e="default"in e?e.default:e,t="default"in t?t.default:t,o});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("lodash.merge"),require("object-path")):"function"==typeof define&&define.amd?define(["lodash.merge","object-path"],t):e.createPersistedState=t(e.merge,e.objectPath)}(this,function(e,t){"use strict";function r(r){void 0===r&&(r={});var n=r.key;void 0===n&&(n="vuex");var o=r.paths;void 0===o&&(o=[]);var a=r.getState;void 0===a&&(a=function(e){return JSON.parse(localStorage.getItem(e))});var i=r.setState;return void 0===i&&(i=function(e,t){return localStorage.setItem(e,JSON.stringify(t))}),function(r){r.replaceState(e({},r.state,a(n))),r.subscribe(function(e,r){var a=0===o.length?r:o.reduce(function(e,n){return t.set(e,n,t.get(r,n)),e},{});i(n,a)})}}return e="default"in e?e.default:e,t="default"in t?t.default:t,r});
{
"name": "vuex-persistedstate",
"description": "Persist Vuex state with localStorage.",
"version": "0.2.0",
"version": "0.3.0",
"license": "MIT",

@@ -27,3 +27,4 @@ "author": "Robin van der Vleuten <robin@webstronauts.co>",

"scripts": {
"build": "rollup --environment NODE_ENV:production -c build/rollup.config.js && uglifyjs dist/vuex-persistedstate.js -cm --comments -o dist/vuex-persistedstate.min.js"
"build": "rollup --environment NODE_ENV:production -c build/rollup.config.js && uglifyjs dist/vuex-persistedstate.js -cm --comments -o dist/vuex-persistedstate.min.js",
"test": "npm run build && karma start karma.conf.js"
},

@@ -35,8 +36,15 @@ "dependencies": {

"devDependencies": {
"browserify": "^13.1.0",
"jasmine-core": "^2.5.2",
"karma": "^1.3.0",
"karma-browserify": "^5.1.0",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-spec-reporter": "0.0.26",
"phantomjs-prebuilt": "^2.1.12",
"rollup": "^0.36.0",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-buble": "^0.14.0",
"rollup-plugin-commonjs": "^5.0.4",
"uglify-js": "^2.7.3"
"uglify-js": "^2.7.3",
"watchify": "^3.7.0"
}
}

@@ -5,4 +5,7 @@ # vuex-persistedstate

## Installation
[![NPM version](https://img.shields.io/npm/v/vuex-persistedstate.svg?style=flat-square)](https://www.npmjs.com/package/vuex-persistedstate)
[![Build Status](https://img.shields.io/travis/robinvdvleuten/vuex-persistedstate.svg?style=flat-square)](https://travis-ci.org/robinvdvleuten/vuex-persistedstate)
### Installation
```bash

@@ -12,3 +15,3 @@ $ npm install vuex-persistedstate

## Usage
### Usage

@@ -20,8 +23,20 @@ ```js

// ...
plugins: [createcreatePersistedState()]
plugins: [createPersistedState()]
})
```
## License
### API
#### `createPersistedState([options])`
Creates a new instance of the plugin with the given options. The following options
can be provided to configure the plugin for your specific needs:
- `key <String>`: The key to store the persisted state under. (default: __vuex__)
- `paths <Array>`: An array of any paths to partially persist the state. If no paths are given, the complete state is persisted. (default: __[]__)
- `getState <Function>`: A function that will be called to rehydrate a previously persisted state. Defaults to localStorage.
- `setState <Function>`: A function that will be called to persist the given state. Defaults to localStorage.
### License
[MIT](http://opensource.org/licenses/MIT)
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