Socket
Socket
Sign inDemoInstall

kea-localstorage

Package Overview
Dependencies
9
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

30

lib/__tests__/index.js

@@ -208,3 +208,33 @@ "use strict";

});
test('can set persistence key', function () {
var storageEngine = {};
kea_1.resetContext({
createStore: true,
plugins: [index_1.localStoragePlugin({ storageEngine: storageEngine })],
});
var anotherLogicWithStorage = kea_1.kea([
kea_1.path(['scenes', 'persist', 'index']),
kea_1.props({}),
kea_1.actions({
setNumber: function (number) { return ({ number: number }); },
}),
kea_1.reducers(function (_a) {
var props = _a.props;
return ({
number: [
12,
{ persist: true, storageKey: "global.storageKey." + props.persistKey },
{
setNumber: function (_, payload) { return payload.number; },
},
],
});
}),
]);
anotherLogicWithStorage({ persistKey: 'banana' }).mount();
expect(kea_1.getPluginContext('localStorage').storageEngine).toBeDefined();
expect(kea_1.getPluginContext('localStorage').storageEngine).toBe(storageEngine);
expect(storageEngine['global.storageKey.banana']).toEqual(12);
});
});
//# sourceMappingURL=index.js.map

1

lib/index.d.ts

@@ -11,2 +11,3 @@ import { KeaPlugin, Logic, ReducerActions, ReducerDefault, LogicBuilder } from 'kea';

separator?: string;
storageKey?: string;
};

@@ -13,0 +14,0 @@ export declare type PersistentReducerDefinitions<L extends Logic> = {

22

lib/index.js
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -42,9 +47,10 @@ exports.persistentReducers = exports.persistReducer = exports.localStoragePlugin = void 0;

return function (logic) {
var _a, _b, _c, _d, _e, _f, _g;
var _h, _j, _k;
var _a, _b, _c, _d, _e, _f, _g, _h;
var _j, _k, _l;
var key_ = key;
var _l = kea_1.getPluginContext('localStorage'), storageCache = _l.storageCache, storageEngine = _l.storageEngine, __prefix = _l.prefix, __separator = _l.separator;
var _m = kea_1.getPluginContext('localStorage'), storageCache = _m.storageCache, storageEngine = _m.storageEngine, __prefix = _m.prefix, __separator = _m.separator;
var prefix = ((_a = logic.reducerOptions[key_]) === null || _a === void 0 ? void 0 : _a.prefix) || __prefix;
var separator = ((_b = logic.reducerOptions[key_]) === null || _b === void 0 ? void 0 : _b.separator) || __separator;
var path = "" + (prefix ? prefix + separator : '') + logic.path.join(separator) + separator + key;
var storageKey = ((_c = logic.reducerOptions[key_]) === null || _c === void 0 ? void 0 : _c.storageKey) || __spreadArray(__spreadArray([], logic.path), [key]).join(separator);
var path = "" + (prefix ? prefix + separator : '') + storageKey;
if (!storageEngine) {

@@ -56,5 +62,5 @@ throw new Error("[KEA] LocalStorage plugin requires a \"storageEngine\"");

}
(_c = (_h = logic.cache).localStorage) !== null && _c !== void 0 ? _c : (_h.localStorage = {});
(_d = (_j = logic.cache).localStorageDefaults) !== null && _d !== void 0 ? _d : (_j.localStorageDefaults = {});
(_e = (_k = logic.cache.localStorageDefaults)[key]) !== null && _e !== void 0 ? _e : (_k[key] = (_f = logic.defaults[key]) !== null && _f !== void 0 ? _f : null);
(_d = (_j = logic.cache).localStorage) !== null && _d !== void 0 ? _d : (_j.localStorage = {});
(_e = (_k = logic.cache).localStorageDefaults) !== null && _e !== void 0 ? _e : (_k.localStorageDefaults = {});
(_f = (_l = logic.cache.localStorageDefaults)[key]) !== null && _f !== void 0 ? _f : (_l[key] = (_g = logic.defaults[key]) !== null && _g !== void 0 ? _g : null);
if (typeof storageEngine[path] !== 'undefined') {

@@ -69,3 +75,3 @@ try {

else {
storageEngine[path] = (_g = logic.defaults[key]) !== null && _g !== void 0 ? _g : null;
storageEngine[path] = (_h = logic.defaults[key]) !== null && _h !== void 0 ? _h : null;
}

@@ -72,0 +78,0 @@ storageCache[path] = logic.defaults[key];

{
"name": "kea-localstorage",
"version": "3.0.0",
"version": "3.1.0",
"description": "Store reducer state in localStorage with Kea",

@@ -5,0 +5,0 @@ "author": "Marius Andra",

@@ -80,12 +80,11 @@ ![NPM Version](https://img.shields.io/npm/v/kea-thunk.svg)

```js
const someLogic = kea({
path: () => ['scenes', 'something', 'foobar'],
const someLogic = kea([
path(['scenes', 'something', 'foobar']),
reducers: ({ actions }) => ({
// somewhere in your kea logic reducers
reducers({
persistedValue: [0, { persist: true, prefix: 'example', separator: '_' }, {
[actions.change]: (_, payload) => payload.value
changeThing: (_, payload) => payload.value
}]
})
})
}),
])
```

@@ -103,1 +102,17 @@

```
### `storageKey`
Pass a `storageKey`, to override the key used for storage. This allows multiple logics to share the same value. For example
to have all keyed logics store a reducer globally.
```js
const someLogic = kea([
key(props => props.key), // not used for localstorage, overridden by storageKey
reducers(({ actions }) => ({
persistedValue: [0, { persist: true, storageKey: 'my.global.key' }, {
[actions.change]: (_, payload) => payload.value
}]
}))
])
```

@@ -34,2 +34,3 @@ import {

separator?: string
storageKey?: string
}

@@ -78,3 +79,4 @@

const separator = logic.reducerOptions[key_]?.separator || __separator
const path = `${prefix ? prefix + separator : ''}${logic.path.join(separator)}${separator}${key}`
const storageKey = logic.reducerOptions[key_]?.storageKey || [...logic.path, key].join(separator)
const path = `${prefix ? prefix + separator : ''}${storageKey}`

@@ -81,0 +83,0 @@ if (!storageEngine) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc