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 - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

.babelrc

89

lib/index.js

@@ -1,7 +0,28 @@

import debug from 'debug';
import Immutable from 'immutable';
'use strict';
class LocalCache {
constructor(store, key = store.displayName) {
this.debug = debug('localstore:' + key).bind(null, '');
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
Object.defineProperty(exports, "__esModule", {
value: true
});
var _debug = require('debug');
var _debug2 = _interopRequireDefault(_debug);
var _immutable = require('immutable');
var _immutable2 = _interopRequireDefault(_immutable);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var LocalStore = (function () {
function LocalStore(store) {
var key = arguments.length <= 1 || arguments[1] === undefined ? store.displayName : arguments[1];
_classCallCheck(this, LocalStore);
this.debug = (0, _debug2.default)('localstore:' + key).bind(null, '');
this.debug('registering localStorage');

@@ -17,27 +38,37 @@

listen() {
this.debug('attaching listener');
this.store.listen(this.save);
}
_createClass(LocalStore, [{
key: 'listen',
value: function listen() {
this.debug('attaching listener');
this.store.listen(this.save);
}
}, {
key: 'unlisten',
value: function unlisten() {
this.debug('detaching listener');
this.store.unlisten(this.save);
}
}, {
key: 'save',
value: function save(data) {
var saveState = data || this.store.state || _immutable2.default.Map();
var stateStr = JSON.stringify(saveState.toJS());
this.debug('saving store state to localStorage', stateStr);
localStorage.setItem(this.key, stateStr);
}
}, {
key: 'restore',
value: function restore() {
var state = JSON.parse(localStorage.getItem(this.key) || '{}');
this.store.setState(function (old) {
return old.merge(_immutable2.default.fromJS(state));
});
this.debug('loading store state from localStorage', state);
return this.store.state;
}
}]);
unlisten() {
this.debug('detaching listener');
this.store.unlisten(this.save);
}
return LocalStore;
})();
save(data) {
let saveState = data || this.store.state || Immutable.Map();
let stateStr = JSON.stringify(saveState.toJS());
this.debug('saving store state to localStorage', stateStr);
localStorage.setItem(this.key, stateStr);
}
restore() {
let state = JSON.parse(localStorage.getItem(this.key) || '{}');
this.store.setState(old => old.merge(Immutable.fromJS(state)));
this.debug('loading store state from localStorage', state);
return this.store.state;
}
}
export default LocalCache;
exports.default = LocalStore;
{
"name": "alt-localstore",
"version": "1.2.1",
"version": "1.2.2",
"description": "save and restore alt store state to localStorage, listens to changes",

@@ -34,4 +34,5 @@ "main": "lib/index.js",

"devDependencies": {
"babel-cli": "^6.0.14"
"babel-cli": "^6.0.14",
"babel-preset-es2015": "^6.0.15"
}
}

@@ -60,2 +60,2 @@ # Alt LocalStore

## 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'`
Source code is written in es6 and is transpiled to es5 on npm publish. Default import retrieves the babel transpiled es5 version. The es6 source code can be found in `src/index.js`.
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