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

redux-local-storage

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-local-storage - npm Package Compare versions

Comparing version 1.6.1 to 1.7.0

.swcrc

28

dist/action_types.js

@@ -1,8 +0,24 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var LOCAL_SET = exports.LOCAL_SET = 'LOCAL_SET';
var LOCAL_GET = exports.LOCAL_GET = 'LOCAL_GET';
var LOCAL_REMOVE = exports.LOCAL_REMOVE = 'LOCAL_REMOVE';
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
LOCAL_SET: function() {
return LOCAL_SET;
},
LOCAL_GET: function() {
return LOCAL_GET;
},
LOCAL_REMOVE: function() {
return LOCAL_REMOVE;
}
});
var LOCAL_SET = "LOCAL_SET";
var LOCAL_GET = "LOCAL_GET";
var LOCAL_REMOVE = "LOCAL_REMOVE";

@@ -1,156 +0,270 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _localforage = require('localforage');
var _localforage2 = _interopRequireDefault(_localforage);
var _action_types = require('./action_types');
var actionTypes = _interopRequireWildcard(_action_types);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var defaultClient = _localforage2.default.createInstance({
name: 'local',
storeName: 'cache'
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
exports.default = function () {
var client = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultClient;
return function (store) {
return function (next) {
return function (action) {
var _action$type$match = action.type.match(/([\a-z0-9_\.]*)?\/?([A-Z0-9_]*)/),
_action$type$match2 = _slicedToArray(_action$type$match, 3),
namespace = _action$type$match2[1],
type = _action$type$match2[2];
var cid = action.cid ? { cid: action.cid } : {};
switch (type) {
case actionTypes.LOCAL_SET:
coerceArray(action.request).map(function (requestAction) {
store.dispatch(_extends({
type: withNamespace(namespace, requestAction)
}, action.meta, cid, {
key: action.key,
value: action.value
}));
var _lodash = /*#__PURE__*/ _interopRequireDefault(require("lodash"));
var _localforage = /*#__PURE__*/ _interopRequireDefault(require("localforage"));
var _actionTypes = /*#__PURE__*/ _interopRequireWildcard(require("./action_types"));
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _objectSpread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
return client.setItem(action.key, action.value, function (err, value) {
if (err) {
coerceArray(action.failure).map(function (failureAction) {
store.dispatch(_extends({
type: withNamespace(namespace, failureAction)
}, action.meta, cid, {
err: err
}));
});
}
coerceArray(action.success).map(function (successAction) {
store.dispatch(_extends({
type: withNamespace(namespace, successAction)
}, action.meta, cid, {
value: value
}));
});
});
case actionTypes.LOCAL_GET:
coerceArray(action.request).map(function (requestAction) {
store.dispatch(_extends({
type: withNamespace(namespace, requestAction)
}, action.meta, cid, {
key: action.key
}));
});
return client.getItem(action.key, function (err, value) {
if (err) {
coerceArray(action.failure).map(function (failureAction) {
store.dispatch(_extends({
type: withNamespace(namespace, failureAction)
}, action.meta, cid, {
err: err
}));
});
}
coerceArray(action.success).map(function (successAction) {
store.dispatch(_extends({
type: withNamespace(namespace, successAction)
}, action.meta, cid, {
value: value
}));
});
});
case actionTypes.LOCAL_REMOVE:
coerceArray(action.request).map(function (requestAction) {
store.dispatch(_extends({
type: withNamespace(namespace, requestAction)
}, action.meta, cid, {
key: action.key
}));
});
return client.removeItem(action.key, function (err, value) {
if (err) {
coerceArray(action.failure).map(function (failureAction) {
store.dispatch(_extends({
type: withNamespace(namespace, failureAction)
}, action.meta, cid, {
err: err
}));
});
}
coerceArray(action.success).map(function (successAction) {
store.dispatch(_extends({
type: withNamespace(namespace, successAction)
}, action.meta, cid));
});
});
default:
return next(action);
}
};
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpreadProps(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
var defaultClient = _localforage.default.createInstance({
name: "local",
storeName: "cache"
});
var _default = function() {
var client = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultClient;
return function(store) {
return function(next) {
return function(action) {
var ref = _slicedToArray(action.type.match(/([\a-z0-9_\.]*)?\/?([A-Z0-9_]*)/), 3), namespace = ref[1], type = ref[2];
var cid = action.cid ? {
cid: action.cid
} : {};
switch(type){
case _actionTypes.LOCAL_SET:
coerceArray(action.request).map(function(requestAction) {
store.dispatch(_objectSpreadProps(_objectSpread({
type: withNamespace(namespace, requestAction)
}, action.meta, cid), {
key: action.key,
value: action.value
}));
});
return client.setItem(action.key, action.value, function(err, value) {
if (err) {
coerceArray(action.failure).map(function(failureAction) {
store.dispatch(_objectSpreadProps(_objectSpread({
type: withNamespace(namespace, failureAction)
}, action.meta, cid), {
err: err
}));
});
if (action.onFailure) action.onFailure(result);
} else {
coerceArray(action.success).map(function(successAction) {
store.dispatch(_objectSpreadProps(_objectSpread({
type: withNamespace(namespace, successAction)
}, action.meta, cid), {
value: value
}));
});
if (action.onSuccess) action.onSuccess(result);
}
});
case _actionTypes.LOCAL_GET:
coerceArray(action.request).map(function(requestAction) {
store.dispatch(_objectSpreadProps(_objectSpread({
type: withNamespace(namespace, requestAction)
}, action.meta, cid), {
key: action.key
}));
});
return client.getItem(action.key, function(err, value) {
if (err) {
coerceArray(action.failure).map(function(failureAction) {
store.dispatch(_objectSpreadProps(_objectSpread({
type: withNamespace(namespace, failureAction)
}, action.meta, cid), {
err: err
}));
});
if (action.onFailure) action.onFailure(result);
} else {
coerceArray(action.success).map(function(successAction) {
store.dispatch(_objectSpreadProps(_objectSpread({
type: withNamespace(namespace, successAction)
}, action.meta, cid), {
value: value
}));
});
if (action.onSuccess) action.onSuccess(result);
}
});
case _actionTypes.LOCAL_REMOVE:
coerceArray(action.request).map(function(requestAction) {
store.dispatch(_objectSpreadProps(_objectSpread({
type: withNamespace(namespace, requestAction)
}, action.meta, cid), {
key: action.key
}));
});
return client.removeItem(action.key, function(err, value) {
if (err) {
coerceArray(action.failure).map(function(failureAction) {
store.dispatch(_objectSpreadProps(_objectSpread({
type: withNamespace(namespace, failureAction)
}, action.meta, cid), {
err: err
}));
});
if (action.onFailure) action.onFailure(result);
} else {
coerceArray(action.success).map(function(successAction) {
store.dispatch(_objectSpread({
type: withNamespace(namespace, successAction)
}, action.meta, cid));
});
if (action.onSuccess) action.onSuccess(result);
}
});
default:
return next(action);
}
};
};
};
};
};
var coerceArray = function coerceArray(value) {
return value ? !_lodash2.default.isArray(value) ? [value] : value : [];
var coerceArray = function(value) {
return value ? !_lodash.default.isArray(value) ? [
value
] : value : [];
};
var withNamespace = function withNamespace(namespace, type) {
return namespace ? namespace + '/' + type : type;
};
var withNamespace = function(namespace, type) {
return namespace ? "".concat(namespace, "/").concat(type) : type;
};

@@ -1,268 +0,264 @@

'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _chai = require('chai');
var _index = require('./index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _chai = require("chai");
var _index = /*#__PURE__*/ _interopRequireDefault(require("./index"));
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _objectSpread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpreadProps(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
var mockLocalStorage = {
setItem: function setItem(key, value, cb) {
var err = key === 'err' ? 'err' : null;
cb(err, value);
},
getItem: function getItem(key, cb) {
var err = key === 'err' ? 'err' : null;
cb(err, 'bar');
},
removeItem: function removeItem(key, cb) {
var err = key === 'err' ? 'err' : null;
cb(err);
}
setItem: function(key, value, cb) {
var err = key === "err" ? "err" : null;
cb(err, value);
},
getItem: function(key, cb) {
var err = key === "err" ? "err" : null;
cb(err, "bar");
},
removeItem: function(key, cb) {
var err = key === "err" ? "err" : null;
cb(err);
}
};
var middleware = (0, _index2.default)(mockLocalStorage);
describe('local middleware', function () {
it('allows non local actions to pass through', function (done) {
var store = {};
var next = function next() {
done();
};
var action = {
type: 'foo/BAR'
};
middleware(store)(next)(action);
});
describe('set', function () {
var successAction = {
type: 'foo/LOCAL_SET',
key: 'foo',
value: 'bar'
};
var failureAction = {
type: 'foo/LOCAL_SET',
key: 'err',
value: 'err'
};
it('dispatches as single request', function (done) {
return dispatchesSingleAction(successAction, 'request', done);
var middleware = (0, _index.default)(mockLocalStorage);
describe("local middleware", function() {
it("allows non local actions to pass through", function(done) {
var store = {};
var next = function() {
done();
};
var action = {
type: "foo/BAR"
};
middleware(store)(next)(action);
});
it('dispatches as mulitple request', function (done) {
return dispatchesMultipleActions(successAction, 'request', done);
describe("set", function() {
var successAction = {
type: "foo/LOCAL_SET",
key: "foo",
value: "bar"
};
var failureAction = {
type: "foo/LOCAL_SET",
key: "err",
value: "err"
};
it("dispatches as single request", function(done) {
return dispatchesSingleAction(successAction, "request", done);
});
it("dispatches as mulitple request", function(done) {
return dispatchesMultipleActions(successAction, "request", done);
});
it("dispatches as single success", function(done) {
return dispatchesSingleAction(successAction, "success", done);
});
it("dispatches as mulitple success", function(done) {
return dispatchesMultipleActions(successAction, "success", done);
});
it("dispatches as single failure", function(done) {
return dispatchesSingleAction(failureAction, "failure", done);
});
it("dispatches as mulitple failure", function(done) {
return dispatchesMultipleActions(failureAction, "failure", done);
});
it("request returns appropriate value", function(done) {
return returnsAppropriateValue(successAction, "request", {
key: "foo",
value: "bar"
}, done);
});
it("success returns appropriate value", function(done) {
return returnsAppropriateValue(successAction, "success", {
value: "bar"
}, done);
});
it("failure returns appropriate value", function(done) {
return returnsAppropriateValue(failureAction, "failure", {
err: "err"
}, done);
});
});
it('dispatches as single success', function (done) {
return dispatchesSingleAction(successAction, 'success', done);
describe("get", function() {
var successAction = {
type: "foo/LOCAL_GET",
key: "foo"
};
var failureAction = {
type: "foo/LOCAL_GET",
key: "err"
};
it("dispatches as single request", function(done) {
return dispatchesSingleAction(successAction, "request", done);
});
it("dispatches as mulitple request", function(done) {
return dispatchesMultipleActions(successAction, "request", done);
});
it("dispatches as single success", function(done) {
return dispatchesSingleAction(successAction, "success", done);
});
it("dispatches as mulitple success", function(done) {
return dispatchesMultipleActions(successAction, "success", done);
});
it("dispatches as single failure", function(done) {
return dispatchesSingleAction(failureAction, "failure", done);
});
it("dispatches as mulitple failure", function(done) {
return dispatchesMultipleActions(failureAction, "failure", done);
});
it("request returns appropriate value", function(done) {
return returnsAppropriateValue(successAction, "request", {
key: "foo"
}, done);
});
it("success returns appropriate value", function(done) {
return returnsAppropriateValue(successAction, "success", {
value: "bar"
}, done);
});
it("failure returns appropriate value", function(done) {
return returnsAppropriateValue(failureAction, "failure", {
err: "err"
}, done);
});
});
it('dispatches as mulitple success', function (done) {
return dispatchesMultipleActions(successAction, 'success', done);
describe("remove", function() {
var successAction = {
type: "foo/LOCAL_REMOVE",
key: "foo"
};
var failureAction = {
type: "foo/LOCAL_REMOVE",
key: "err"
};
it("dispatches as single request", function(done) {
return dispatchesSingleAction(successAction, "request", done);
});
it("dispatches as mulitple request", function(done) {
return dispatchesMultipleActions(successAction, "request", done);
});
it("dispatches as single success", function(done) {
return dispatchesSingleAction(successAction, "success", done);
});
it("dispatches as mulitple success", function(done) {
return dispatchesMultipleActions(successAction, "success", done);
});
it("dispatches as single failure", function(done) {
return dispatchesSingleAction(failureAction, "failure", done);
});
it("dispatches as mulitple failure", function(done) {
return dispatchesMultipleActions(failureAction, "failure", done);
});
it("request returns appropriate value", function(done) {
return returnsAppropriateValue(successAction, "request", {
key: "foo"
}, done);
});
it("success returns appropriate value", function(done) {
return returnsAppropriateValue(successAction, "success", {}, done);
});
it("failure returns appropriate value", function(done) {
return returnsAppropriateValue(failureAction, "failure", {
err: "err"
}, done);
});
});
it('dispatches as single failure', function (done) {
return dispatchesSingleAction(failureAction, 'failure', done);
});
it('dispatches as mulitple failure', function (done) {
return dispatchesMultipleActions(failureAction, 'failure', done);
});
it('request returns appropriate value', function (done) {
return returnsAppropriateValue(successAction, 'request', { key: 'foo', value: 'bar' }, done);
});
it('success returns appropriate value', function (done) {
return returnsAppropriateValue(successAction, 'success', { value: 'bar' }, done);
});
it('failure returns appropriate value', function (done) {
return returnsAppropriateValue(failureAction, 'failure', { err: 'err' }, done);
});
});
describe('get', function () {
var successAction = {
type: 'foo/LOCAL_GET',
key: 'foo'
});
var returnsAppropriateValue = function(action, type, value, done) {
var store = {
dispatch: function(action) {
if (action.type === "foo/".concat(type.toUpperCase())) {
(0, _chai.expect)(action).to.eql(_objectSpread({
type: "foo/".concat(type.toUpperCase())
}, value));
done();
}
}
};
var failureAction = {
type: 'foo/LOCAL_GET',
key: 'err'
var next = function() {};
var actionWithCallback = _objectSpreadProps(_objectSpread({}, action), _defineProperty({}, type, "".concat(type.toUpperCase())));
middleware(store)(next)(actionWithCallback);
};
var dispatchesSingleAction = function(action, actionType, done) {
var store = {
dispatch: function(action) {
if (action.type === "foo/".concat(actionType.toUpperCase())) {
done();
}
}
};
it('dispatches as single request', function (done) {
return dispatchesSingleAction(successAction, 'request', done);
});
it('dispatches as mulitple request', function (done) {
return dispatchesMultipleActions(successAction, 'request', done);
});
it('dispatches as single success', function (done) {
return dispatchesSingleAction(successAction, 'success', done);
});
it('dispatches as mulitple success', function (done) {
return dispatchesMultipleActions(successAction, 'success', done);
});
it('dispatches as single failure', function (done) {
return dispatchesSingleAction(failureAction, 'failure', done);
});
it('dispatches as mulitple failure', function (done) {
return dispatchesMultipleActions(failureAction, 'failure', done);
});
it('request returns appropriate value', function (done) {
return returnsAppropriateValue(successAction, 'request', { key: 'foo' }, done);
});
it('success returns appropriate value', function (done) {
return returnsAppropriateValue(successAction, 'success', { value: 'bar' }, done);
});
it('failure returns appropriate value', function (done) {
return returnsAppropriateValue(failureAction, 'failure', { err: 'err' }, done);
});
});
describe('remove', function () {
var successAction = {
type: 'foo/LOCAL_REMOVE',
key: 'foo'
var next = function() {};
var actionWithCallback = _objectSpreadProps(_objectSpread({}, action), _defineProperty({}, actionType, actionType.toUpperCase()));
middleware(store)(next)(actionWithCallback);
};
var dispatchesMultipleActions = function(action, actionType, done) {
var store = {
dispatch: function(action) {
if (action.type === "foo/${actionType.toUpperCase()}2") {
done();
}
}
};
var failureAction = {
type: 'foo/LOCAL_REMOVE',
key: 'err'
};
it('dispatches as single request', function (done) {
return dispatchesSingleAction(successAction, 'request', done);
var next = function() {};
var actionWithCallback = _objectSpreadProps(_objectSpread({}, action), {
request: [
"${actionType.toUpperCase()}1",
"${actionType.toUpperCase()}2"
]
});
it('dispatches as mulitple request', function (done) {
return dispatchesMultipleActions(successAction, 'request', done);
});
it('dispatches as single success', function (done) {
return dispatchesSingleAction(successAction, 'success', done);
});
it('dispatches as mulitple success', function (done) {
return dispatchesMultipleActions(successAction, 'success', done);
});
it('dispatches as single failure', function (done) {
return dispatchesSingleAction(failureAction, 'failure', done);
});
it('dispatches as mulitple failure', function (done) {
return dispatchesMultipleActions(failureAction, 'failure', done);
});
it('request returns appropriate value', function (done) {
return returnsAppropriateValue(successAction, 'request', { key: 'foo' }, done);
});
it('success returns appropriate value', function (done) {
return returnsAppropriateValue(successAction, 'success', {}, done);
});
it('failure returns appropriate value', function (done) {
return returnsAppropriateValue(failureAction, 'failure', { err: 'err' }, done);
});
});
});
var returnsAppropriateValue = function returnsAppropriateValue(action, type, value, done) {
var store = {
dispatch: function dispatch(action) {
if (action.type === 'foo/' + type.toUpperCase()) {
(0, _chai.expect)(action).to.eql(_extends({
type: 'foo/' + type.toUpperCase()
}, value));
done();
}
}
};
var next = function next() {};
var actionWithCallback = _extends({}, action, _defineProperty({}, type, '' + type.toUpperCase()));
middleware(store)(next)(actionWithCallback);
middleware(store)(next)(actionWithCallback);
};
var dispatchesSingleAction = function dispatchesSingleAction(action, actionType, done) {
var store = {
dispatch: function dispatch(action) {
if (action.type === 'foo/' + actionType.toUpperCase()) {
done();
}
}
};
var next = function next() {};
var actionWithCallback = _extends({}, action, _defineProperty({}, actionType, actionType.toUpperCase()));
middleware(store)(next)(actionWithCallback);
};
var dispatchesMultipleActions = function dispatchesMultipleActions(action, actionType, done) {
var store = {
dispatch: function dispatch(action) {
if (action.type === 'foo/${actionType.toUpperCase()}2') {
done();
}
}
};
var next = function next() {};
var actionWithCallback = _extends({}, action, {
request: ['${actionType.toUpperCase()}1', '${actionType.toUpperCase()}2']
});
middleware(store)(next)(actionWithCallback);
};
{
"name": "redux-local-storage",
"version": "1.6.1",
"version": "1.7.0",
"description": "Redux middleware for accessing local storage",

@@ -11,3 +11,3 @@ "license": "ISC",

"scripts": {
"build": "rm -rf ./dist && babel ./src --out-dir ./dist",
"build": "rm -rf ./dist && npx swc ./src -d ./dist",
"coverage": "NODE_ENV=test NODE_PATH=./src nyc --reporter=lcov --reporter=text --recursive --require babel-core/register mocha ./src/tests.js",

@@ -17,3 +17,2 @@ "test": "NODE_ENV=test NODE_PATH=./src mocha --recursive --require babel-core/register ./src/tests.js"

"keywords": [
"react",
"redux",

@@ -25,7 +24,4 @@ "local storage",

"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"@swc/cli": "^0.1.57",
"@swc/core": "^1.2.218",
"chai": "^3.5.0",

@@ -42,5 +38,4 @@ "eslint": "^3.19.0",

"peerDependencies": {
"react": "^16.x",
"redux": "^3.x"
}
}

@@ -43,13 +43,15 @@ import _ from 'lodash'

})
if(action.onFailure) action.onFailure(result)
} else {
coerceArray(action.success).map(successAction => {
store.dispatch({
type: withNamespace(namespace, successAction),
...action.meta,
...cid,
value
})
})
if(action.onSuccess) action.onSuccess(result)
}
coerceArray(action.success).map(successAction => {
store.dispatch({
type: withNamespace(namespace, successAction),
...action.meta,
...cid,
value
})
})
})

@@ -79,13 +81,15 @@

})
if(action.onFailure) action.onFailure(result)
} else {
coerceArray(action.success).map(successAction => {
store.dispatch({
type: withNamespace(namespace, successAction),
...action.meta,
...cid,
value
})
})
if(action.onSuccess) action.onSuccess(result)
}
coerceArray(action.success).map(successAction => {
store.dispatch({
type: withNamespace(namespace, successAction),
...action.meta,
...cid,
value
})
})
})

@@ -115,12 +119,14 @@

})
if(action.onFailure) action.onFailure(result)
} else {
coerceArray(action.success).map(successAction => {
store.dispatch({
type: withNamespace(namespace, successAction),
...action.meta,
...cid
})
})
if(action.onSuccess) action.onSuccess(result)
}
coerceArray(action.success).map(successAction => {
store.dispatch({
type: withNamespace(namespace, successAction),
...action.meta,
...cid
})
})
})

@@ -127,0 +133,0 @@

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