redux-astroglide 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,422 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["redux-astroglide/plugins"] = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- var index$2 = (function (callback) {
8
- return {
9
- constructor: function constructor(innerCallback, value) {
10
- this.value = value;
11
- this.callback = innerCallback || callback;
12
- },
13
- update: function update(value, _ref) {
14
- var draft = _ref.draft,
15
- plugin = _ref.plugin;
16
- return plugin.callback(value, {
17
- draft: draft
18
- });
19
- }
20
- };
21
- });
22
-
23
- function ownKeys(e, r) {
24
- var t = Object.keys(e);
25
- if (Object.getOwnPropertySymbols) {
26
- var o = Object.getOwnPropertySymbols(e);
27
- r && (o = o.filter(function (r) {
28
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
29
- })), t.push.apply(t, o);
30
- }
31
- return t;
32
- }
33
- function _objectSpread2(e) {
34
- for (var r = 1; r < arguments.length; r++) {
35
- var t = null != arguments[r] ? arguments[r] : {};
36
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
37
- _defineProperty(e, r, t[r]);
38
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
39
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
40
- });
41
- }
42
- return e;
43
- }
44
- function _classCallCheck(instance, Constructor) {
45
- if (!(instance instanceof Constructor)) {
46
- throw new TypeError("Cannot call a class as a function");
47
- }
48
- }
49
- function _defineProperties(target, props) {
50
- for (var i = 0; i < props.length; i++) {
51
- var descriptor = props[i];
52
- descriptor.enumerable = descriptor.enumerable || false;
53
- descriptor.configurable = true;
54
- if ("value" in descriptor) descriptor.writable = true;
55
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
56
- }
57
- }
58
- function _createClass(Constructor, protoProps, staticProps) {
59
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
60
- if (staticProps) _defineProperties(Constructor, staticProps);
61
- Object.defineProperty(Constructor, "prototype", {
62
- writable: false
63
- });
64
- return Constructor;
65
- }
66
- function _defineProperty(obj, key, value) {
67
- key = _toPropertyKey(key);
68
- if (key in obj) {
69
- Object.defineProperty(obj, key, {
70
- value: value,
71
- enumerable: true,
72
- configurable: true,
73
- writable: true
74
- });
75
- } else {
76
- obj[key] = value;
77
- }
78
- return obj;
79
- }
80
- function _setPrototypeOf(o, p) {
81
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
82
- o.__proto__ = p;
83
- return o;
84
- };
85
- return _setPrototypeOf(o, p);
86
- }
87
- function _isNativeReflectConstruct() {
88
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
89
- if (Reflect.construct.sham) return false;
90
- if (typeof Proxy === "function") return true;
91
- try {
92
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
93
- return true;
94
- } catch (e) {
95
- return false;
96
- }
97
- }
98
- function _construct(Parent, args, Class) {
99
- if (_isNativeReflectConstruct()) {
100
- _construct = Reflect.construct.bind();
101
- } else {
102
- _construct = function _construct(Parent, args, Class) {
103
- var a = [null];
104
- a.push.apply(a, args);
105
- var Constructor = Function.bind.apply(Parent, a);
106
- var instance = new Constructor();
107
- if (Class) _setPrototypeOf(instance, Class.prototype);
108
- return instance;
109
- };
110
- }
111
- return _construct.apply(null, arguments);
112
- }
113
- function _objectDestructuringEmpty(obj) {
114
- if (obj == null) throw new TypeError("Cannot destructure " + obj);
115
- }
116
- function _toPrimitive(input, hint) {
117
- if (typeof input !== "object" || input === null) return input;
118
- var prim = input[Symbol.toPrimitive];
119
- if (prim !== undefined) {
120
- var res = prim.call(input, hint || "default");
121
- if (typeof res !== "object") return res;
122
- throw new TypeError("@@toPrimitive must return a primitive value.");
123
- }
124
- return (hint === "string" ? String : Number)(input);
125
- }
126
- function _toPropertyKey(arg) {
127
- var key = _toPrimitive(arg, "string");
128
- return typeof key === "symbol" ? key : String(key);
129
- }
130
-
131
- var checkPropTypes$1 = {exports: {}};
132
-
133
- /**
134
- * Copyright (c) 2013-present, Facebook, Inc.
135
- *
136
- * This source code is licensed under the MIT license found in the
137
- * LICENSE file in the root directory of this source tree.
138
- */
139
- var ReactPropTypesSecret_1;
140
- var hasRequiredReactPropTypesSecret;
141
- function requireReactPropTypesSecret() {
142
- if (hasRequiredReactPropTypesSecret) return ReactPropTypesSecret_1;
143
- hasRequiredReactPropTypesSecret = 1;
144
- var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
145
- ReactPropTypesSecret_1 = ReactPropTypesSecret;
146
- return ReactPropTypesSecret_1;
147
- }
148
-
149
- /**
150
- * Copyright Facebook, ratehub.
151
- * All rights reserved.
152
- *
153
- * This code is intended to closely match the behaviour of checkPropTypes() from
154
- * facebook/prop-types. The license for that code can be found here:
155
- * https://github.com/facebook/prop-types/blob/be165febc8133dfbe2c45133db6d25664dd68ad8/LICENSE
156
- *
157
- * That function's source:
158
- * https://github.com/facebook/prop-types/blob/be165febc8133dfbe2c45133db6d25664dd68ad8/checkPropTypes.js
159
- */
160
-
161
- /**
162
- * Check if the values match with the type specs
163
- * Return a type error message or null
164
- *
165
- * @param {object} typeSpecs Map of name to a ReactPropType
166
- * @param {object} values Runtime values that need to be type-checked
167
- * @param {string} location e.g. "prop", "context", "child context"
168
- * @param {string} componentName Name of the component for error messages.
169
- * @param {?Function} getStack Returns the component stack.
170
- */
171
- function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
172
- if (process.env.NODE_ENV !== 'production') {
173
- const ReactPropTypesSecret = requireReactPropTypesSecret();
174
- var name = componentName || 'React class';
175
- for (var typeSpecName in typeSpecs) {
176
- if (typeSpecs.hasOwnProperty(typeSpecName)) {
177
- var error;
178
- if (typeof typeSpecs[typeSpecName] !== 'function') {
179
- return name + ': ' + location + ' type `' + typeSpecName + '` is ' + 'invalid; it must be a function, usually from React.PropTypes.';
180
- } else {
181
- // Prop type validation may throw. In case they do, catch and save the
182
- // exception as the error.
183
- try {
184
- error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
185
- } catch (ex) {
186
- error = ex;
187
- }
188
- }
189
- if (error && !(error instanceof Error)) {
190
- return name + ': type specification of ' + location + ' `' + typeSpecName + '` is invalid; the type checker function must ' + 'return `null` or an `Error` but returned a ' + typeof error + '. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).';
191
- }
192
- if (error instanceof Error) {
193
- var stack = getStack && getStack() || '';
194
- return 'Failed ' + location + ' type: ' + error.message + stack;
195
- }
196
- }
197
- }
198
- }
199
- }
200
-
201
- /**
202
- * Same as checkPropTypes but throws on error
203
- */
204
- function assertPropTypes() {
205
- if (process.env.NODE_ENV !== 'production') {
206
- var error = checkPropTypes.apply(null, arguments);
207
- if (error) {
208
- throw new Error(error);
209
- }
210
- }
211
- }
212
- checkPropTypes$1.exports = checkPropTypes;
213
- checkPropTypes$1.exports.assertPropTypes = assertPropTypes;
214
-
215
- var checkPropType = function checkPropType(propType, value, name) {
216
- var extraProps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
217
- return checkPropTypes$1.exports(_defineProperty({}, name, propType), _objectSpread2(_objectSpread2({}, extraProps), {}, _defineProperty({}, name, value)), name, undefined);
218
- };
219
- var checkProp = function checkProp(propType, value, name) {
220
- var shouldTypeErrorPreventUpdate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
221
- var result = checkPropType(propType, value, name);
222
- if (result) {
223
- var errorText = "Astroglide: prop ".concat(name, " with value ").concat(value, " is not of the specified type");
224
- if (shouldTypeErrorPreventUpdate) {
225
- throw Error(errorText);
226
- } else {
227
- console.warn(errorText);
228
- }
229
- return result;
230
- }
231
- return false;
232
- };
233
-
234
- var index$1 = (function () {
235
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
236
- preventUpdate: false
237
- },
238
- preventUpdate = _ref.preventUpdate;
239
- return {
240
- constructor: function constructor(propType, value) {
241
- var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
242
- this.value = value; // value set here because constructor signature is different
243
- this.propType = propType;
244
- this.config = _objectSpread2(_objectSpread2({}, this.config), config);
245
- },
246
- getInitialValue: function getInitialValue(value, _ref2) {
247
- var key = _ref2.key,
248
- plugin = _ref2.plugin;
249
- var propType = plugin.propType;
250
- checkProp(propType, value, key);
251
- return value;
252
- },
253
- update: function update(value, _ref3) {
254
- var key = _ref3.key,
255
- plugin = _ref3.plugin;
256
- var propType = plugin.propType;
257
- checkProp(propType, value, key, plugin.config.preventUpdate !== undefined ? plugin.config.preventUpdate : preventUpdate);
258
- return value;
259
- },
260
- config: {
261
- preventUpdate: false
262
- }
263
- };
264
- });
265
-
266
- var localStorage = (window || {}).localStorage;
267
- var isLocalStorageAvaialble = !!localStorage;
268
- var PERSISTENCE_KEY = "astroglide-persist";
269
- var defaultStorageType = localStorage;
270
- var getPersistedStore = function getPersistedStore() {
271
- var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultStorageType;
272
- return JSON.parse(storage.getItem(PERSISTENCE_KEY) || "{}");
273
- };
274
- var storePersistedValue = function storePersistedValue(key, namespace, value) {
275
- var storage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : localStorage;
276
- var store = getPersistedStore(storage);
277
- if (namespace) {
278
- store[namespace] = store[namespace] || {};
279
- store[namespace][key] = value;
280
- } else {
281
- store[key] = value;
282
- }
283
- try {
284
- storage.setItem(PERSISTENCE_KEY, JSON.stringify(store));
285
- } catch (e) {
286
- console.error(e);
287
- }
288
- };
289
- var getPersistedValue = function getPersistedValue(key, namespace, _storage) {
290
- var _scope2;
291
- var storage = _storage || defaultStorageType;
292
- var scope = getPersistedStore(storage);
293
- if (namespace) {
294
- var _scope;
295
- scope = (_scope = scope) === null || _scope === void 0 ? void 0 : _scope[namespace];
296
- }
297
- return (_scope2 = scope) === null || _scope2 === void 0 ? void 0 : _scope2[key];
298
- };
299
- var index = (function () {
300
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
301
- _ref$storageType = _ref.storageType,
302
- storageType = _ref$storageType === void 0 ? defaultStorageType : _ref$storageType;
303
- if (!isLocalStorageAvaialble && !storageType) {
304
- console.warn("localStorage is not available! You must provide your own storage to persist"); // eslint-disable-line no-console
305
- }
306
-
307
- defaultStorageType = storageType;
308
- return {
309
- setup: function setup(plugin, _ref2) {
310
- var sliceConfig = _ref2.sliceConfig;
311
- return {
312
- namespace: sliceConfig.name,
313
- storageType: storageType
314
- };
315
- },
316
- getInitialValue: function getInitialValue(value, _ref3) {
317
- var sliceConfig = _ref3.sliceConfig,
318
- key = _ref3.key;
319
- var existingPersistedValue = getPersistedValue(key, sliceConfig.name, storageType);
320
- if (existingPersistedValue !== undefined) {
321
- return existingPersistedValue;
322
- }
323
- return value;
324
- },
325
- update: function update(value, _ref4) {
326
- var key = _ref4.key,
327
- sliceConfig = _ref4.sliceConfig;
328
- storePersistedValue(key, sliceConfig.name, value, storageType !== undefined ? storageType : this.config.storageType || defaultStorageType);
329
- return value;
330
- }
331
- };
332
- });
333
-
334
- var plugin = function plugin(_ref) {
335
- var constructorFn = _ref.constructor,
336
- setup = _ref.setup,
337
- getInitialValue = _ref.getInitialValue,
338
- update = _ref.update,
339
- _ref$config = _ref.config,
340
- config = _ref$config === void 0 ? {} : _ref$config;
341
- return /*#__PURE__*/function () {
342
- function _class(value) {
343
- _classCallCheck(this, _class);
344
- this.value = value;
345
- this.setup = setup || this.setup;
346
- this.getInitialValue = getInitialValue || this.getInitialValue;
347
- this.update = update || this.update;
348
- this.config = config;
349
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
350
- args[_key - 1] = arguments[_key];
351
- }
352
- constructorFn === null || constructorFn === void 0 || constructorFn.call.apply(constructorFn, [this, value].concat(args));
353
- }
354
-
355
- // either the initial state value or the next plugin
356
- _createClass(_class, [{
357
- key: "getValue",
358
- value: function getValue() {
359
- return this.value;
360
- }
361
- }, {
362
- key: "setValue",
363
- value: function setValue(value) {
364
- this.value = value;
365
- }
366
- }, {
367
- key: "setConfig",
368
- value: function setConfig(config) {
369
- this.config = _objectSpread2(_objectSpread2({}, this.config), config);
370
- }
371
- }, {
372
- key: "setup",
373
- value: function setup(item, _ref2) {
374
- _objectDestructuringEmpty(_ref2);
375
- return {
376
- plugin: item
377
- };
378
- }
379
- }, {
380
- key: "getInitialValue",
381
- value: function getInitialValue(value, _ref3) {
382
- _objectDestructuringEmpty(_ref3);
383
- return value;
384
- }
385
- }, {
386
- key: "update",
387
- value: function update(value, _ref4) {
388
- _objectDestructuringEmpty(_ref4);
389
- return value;
390
- }
391
- }]);
392
- return _class;
393
- }();
394
- };
395
- var addPlugin = function addPlugin(config) {
396
- var Class = plugin(config);
397
- plugins.push(Class);
398
- return function () {
399
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
400
- args[_key2] = arguments[_key2];
401
- }
402
- return _construct(Class, args);
403
- };
404
- };
405
- var addPlugins = function addPlugins() {
406
- for (var _len3 = arguments.length, configs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
407
- configs[_key3] = arguments[_key3];
408
- }
409
- return configs.map(addPlugin);
410
- };
411
- var plugins = [];
412
-
413
- exports.addPlugin = addPlugin;
414
- exports.addPlugins = addPlugins;
415
- exports.persist = index;
416
- exports.plugins = plugins;
417
- exports.set = index$2;
418
- exports.type = index$1;
419
-
420
- Object.defineProperty(exports, '__esModule', { value: true });
421
-
422
- }));
@@ -1,69 +0,0 @@
1
- var localStorage = (window || {}).localStorage;
2
- var isLocalStorageAvaialble = !!localStorage;
3
- var PERSISTENCE_KEY = "astroglide-persist";
4
- var defaultStorageType = localStorage;
5
- var getPersistedStore = function getPersistedStore() {
6
- var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultStorageType;
7
- return JSON.parse(storage.getItem(PERSISTENCE_KEY) || "{}");
8
- };
9
- var storePersistedValue = function storePersistedValue(key, namespace, value) {
10
- var storage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : localStorage;
11
- var store = getPersistedStore(storage);
12
- if (namespace) {
13
- store[namespace] = store[namespace] || {};
14
- store[namespace][key] = value;
15
- } else {
16
- store[key] = value;
17
- }
18
- try {
19
- storage.setItem(PERSISTENCE_KEY, JSON.stringify(store));
20
- } catch (e) {
21
- console.error(e);
22
- }
23
- };
24
- var getPersistedValue = function getPersistedValue(key, namespace, _storage) {
25
- var _scope2;
26
- var storage = _storage || defaultStorageType;
27
- var scope = getPersistedStore(storage);
28
- if (namespace) {
29
- var _scope;
30
- scope = (_scope = scope) === null || _scope === void 0 ? void 0 : _scope[namespace];
31
- }
32
- return (_scope2 = scope) === null || _scope2 === void 0 ? void 0 : _scope2[key];
33
- };
34
- var index = (function () {
35
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
36
- _ref$storageType = _ref.storageType,
37
- storageType = _ref$storageType === void 0 ? defaultStorageType : _ref$storageType;
38
- if (!isLocalStorageAvaialble && !storageType) {
39
- console.warn("localStorage is not available! You must provide your own storage to persist"); // eslint-disable-line no-console
40
- }
41
-
42
- defaultStorageType = storageType;
43
- return {
44
- setup: function setup(plugin, _ref2) {
45
- var sliceConfig = _ref2.sliceConfig;
46
- return {
47
- namespace: sliceConfig.name,
48
- storageType: storageType
49
- };
50
- },
51
- getInitialValue: function getInitialValue(value, _ref3) {
52
- var sliceConfig = _ref3.sliceConfig,
53
- key = _ref3.key;
54
- var existingPersistedValue = getPersistedValue(key, sliceConfig.name, storageType);
55
- if (existingPersistedValue !== undefined) {
56
- return existingPersistedValue;
57
- }
58
- return value;
59
- },
60
- update: function update(value, _ref4) {
61
- var key = _ref4.key,
62
- sliceConfig = _ref4.sliceConfig;
63
- storePersistedValue(key, sliceConfig.name, value, storageType !== undefined ? storageType : this.config.storageType || defaultStorageType);
64
- return value;
65
- }
66
- };
67
- });
68
-
69
- export { index as default, getPersistedStore, getPersistedValue, storePersistedValue };
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var localStorage = (window || {}).localStorage;
6
- var isLocalStorageAvaialble = !!localStorage;
7
- var PERSISTENCE_KEY = "astroglide-persist";
8
- var defaultStorageType = localStorage;
9
- var getPersistedStore = function getPersistedStore() {
10
- var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultStorageType;
11
- return JSON.parse(storage.getItem(PERSISTENCE_KEY) || "{}");
12
- };
13
- var storePersistedValue = function storePersistedValue(key, namespace, value) {
14
- var storage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : localStorage;
15
- var store = getPersistedStore(storage);
16
- if (namespace) {
17
- store[namespace] = store[namespace] || {};
18
- store[namespace][key] = value;
19
- } else {
20
- store[key] = value;
21
- }
22
- try {
23
- storage.setItem(PERSISTENCE_KEY, JSON.stringify(store));
24
- } catch (e) {
25
- console.error(e);
26
- }
27
- };
28
- var getPersistedValue = function getPersistedValue(key, namespace, _storage) {
29
- var _scope2;
30
- var storage = _storage || defaultStorageType;
31
- var scope = getPersistedStore(storage);
32
- if (namespace) {
33
- var _scope;
34
- scope = (_scope = scope) === null || _scope === void 0 ? void 0 : _scope[namespace];
35
- }
36
- return (_scope2 = scope) === null || _scope2 === void 0 ? void 0 : _scope2[key];
37
- };
38
- var index = (function () {
39
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
40
- _ref$storageType = _ref.storageType,
41
- storageType = _ref$storageType === void 0 ? defaultStorageType : _ref$storageType;
42
- if (!isLocalStorageAvaialble && !storageType) {
43
- console.warn("localStorage is not available! You must provide your own storage to persist"); // eslint-disable-line no-console
44
- }
45
-
46
- defaultStorageType = storageType;
47
- return {
48
- setup: function setup(plugin, _ref2) {
49
- var sliceConfig = _ref2.sliceConfig;
50
- return {
51
- namespace: sliceConfig.name,
52
- storageType: storageType
53
- };
54
- },
55
- getInitialValue: function getInitialValue(value, _ref3) {
56
- var sliceConfig = _ref3.sliceConfig,
57
- key = _ref3.key;
58
- var existingPersistedValue = getPersistedValue(key, sliceConfig.name, storageType);
59
- if (existingPersistedValue !== undefined) {
60
- return existingPersistedValue;
61
- }
62
- return value;
63
- },
64
- update: function update(value, _ref4) {
65
- var key = _ref4.key,
66
- sliceConfig = _ref4.sliceConfig;
67
- storePersistedValue(key, sliceConfig.name, value, storageType !== undefined ? storageType : this.config.storageType || defaultStorageType);
68
- return value;
69
- }
70
- };
71
- });
72
-
73
- exports["default"] = index;
74
- exports.getPersistedStore = getPersistedStore;
75
- exports.getPersistedValue = getPersistedValue;
76
- exports.storePersistedValue = storePersistedValue;
@@ -1,82 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["redux-astroglide/plugins/persist"] = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- var localStorage = (window || {}).localStorage;
8
- var isLocalStorageAvaialble = !!localStorage;
9
- var PERSISTENCE_KEY = "astroglide-persist";
10
- var defaultStorageType = localStorage;
11
- var getPersistedStore = function getPersistedStore() {
12
- var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultStorageType;
13
- return JSON.parse(storage.getItem(PERSISTENCE_KEY) || "{}");
14
- };
15
- var storePersistedValue = function storePersistedValue(key, namespace, value) {
16
- var storage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : localStorage;
17
- var store = getPersistedStore(storage);
18
- if (namespace) {
19
- store[namespace] = store[namespace] || {};
20
- store[namespace][key] = value;
21
- } else {
22
- store[key] = value;
23
- }
24
- try {
25
- storage.setItem(PERSISTENCE_KEY, JSON.stringify(store));
26
- } catch (e) {
27
- console.error(e);
28
- }
29
- };
30
- var getPersistedValue = function getPersistedValue(key, namespace, _storage) {
31
- var _scope2;
32
- var storage = _storage || defaultStorageType;
33
- var scope = getPersistedStore(storage);
34
- if (namespace) {
35
- var _scope;
36
- scope = (_scope = scope) === null || _scope === void 0 ? void 0 : _scope[namespace];
37
- }
38
- return (_scope2 = scope) === null || _scope2 === void 0 ? void 0 : _scope2[key];
39
- };
40
- var index = (function () {
41
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
42
- _ref$storageType = _ref.storageType,
43
- storageType = _ref$storageType === void 0 ? defaultStorageType : _ref$storageType;
44
- if (!isLocalStorageAvaialble && !storageType) {
45
- console.warn("localStorage is not available! You must provide your own storage to persist"); // eslint-disable-line no-console
46
- }
47
-
48
- defaultStorageType = storageType;
49
- return {
50
- setup: function setup(plugin, _ref2) {
51
- var sliceConfig = _ref2.sliceConfig;
52
- return {
53
- namespace: sliceConfig.name,
54
- storageType: storageType
55
- };
56
- },
57
- getInitialValue: function getInitialValue(value, _ref3) {
58
- var sliceConfig = _ref3.sliceConfig,
59
- key = _ref3.key;
60
- var existingPersistedValue = getPersistedValue(key, sliceConfig.name, storageType);
61
- if (existingPersistedValue !== undefined) {
62
- return existingPersistedValue;
63
- }
64
- return value;
65
- },
66
- update: function update(value, _ref4) {
67
- var key = _ref4.key,
68
- sliceConfig = _ref4.sliceConfig;
69
- storePersistedValue(key, sliceConfig.name, value, storageType !== undefined ? storageType : this.config.storageType || defaultStorageType);
70
- return value;
71
- }
72
- };
73
- });
74
-
75
- exports["default"] = index;
76
- exports.getPersistedStore = getPersistedStore;
77
- exports.getPersistedValue = getPersistedValue;
78
- exports.storePersistedValue = storePersistedValue;
79
-
80
- Object.defineProperty(exports, '__esModule', { value: true });
81
-
82
- }));
@@ -1,17 +0,0 @@
1
- var index = (function (callback) {
2
- return {
3
- constructor: function constructor(innerCallback, value) {
4
- this.value = value;
5
- this.callback = innerCallback || callback;
6
- },
7
- update: function update(value, _ref) {
8
- var draft = _ref.draft,
9
- plugin = _ref.plugin;
10
- return plugin.callback(value, {
11
- draft: draft
12
- });
13
- }
14
- };
15
- });
16
-
17
- export { index as default };
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var index = (function (callback) {
4
- return {
5
- constructor: function constructor(innerCallback, value) {
6
- this.value = value;
7
- this.callback = innerCallback || callback;
8
- },
9
- update: function update(value, _ref) {
10
- var draft = _ref.draft,
11
- plugin = _ref.plugin;
12
- return plugin.callback(value, {
13
- draft: draft
14
- });
15
- }
16
- };
17
- });
18
-
19
- module.exports = index;