varstor 0.2.6 → 0.3.6

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.
@@ -58,7 +58,7 @@ function isFunction(x) {
58
58
  }
59
59
 
60
60
  function isObject(x) {
61
- return typeof x === "object";
61
+ return Object.prototype.toString.call(x) === "[object Object]";
62
62
  }
63
63
 
64
64
  function isString(x) {
@@ -195,7 +195,7 @@ function getArguments(computedName) {
195
195
  .concat(values);
196
196
  }
197
197
 
198
- function createAccessor(key, value, storageType) {
198
+ function createAccessor(key, storageType) {
199
199
  const accessor = () => STATE[key].value;
200
200
 
201
201
  Object.assign(accessor, {
@@ -280,7 +280,7 @@ function getState(namespace, arg) {
280
280
  }
281
281
 
282
282
  function getNamespaceValues(namespace) {
283
- return (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.getKeys)((0,_namespace__WEBPACK_IMPORTED_MODULE_2__.getByNamespace)(namespace, STATE), "value");
283
+ return recreateStructure((0,_helpers__WEBPACK_IMPORTED_MODULE_1__.getKeys)((0,_namespace__WEBPACK_IMPORTED_MODULE_2__.getByNamespace)(namespace, STATE), "value"));
284
284
  }
285
285
 
286
286
  function getNamespaceAccessors (namespace, cb) {
@@ -325,6 +325,26 @@ function removeStateListener(namespace, observables, cb) {
325
325
  return createStore(namespace());
326
326
  }
327
327
 
328
+ function recreateStructure (value) {
329
+ let newValue = value;
330
+
331
+ if ((0,_helpers__WEBPACK_IMPORTED_MODULE_1__.isArray)(value)) {
332
+ newValue = [];
333
+ value.forEach((v) => newValue.push(recreateStructure(v)));
334
+ return newValue;
335
+ }
336
+
337
+ if ((0,_helpers__WEBPACK_IMPORTED_MODULE_1__.isObject)(value)) {
338
+ newValue = {};
339
+ for (let key in value) {
340
+ newValue[key] = recreateStructure(value[key]);
341
+ }
342
+ return newValue;
343
+ }
344
+
345
+ return newValue;
346
+ }
347
+
328
348
  function main () {
329
349
  const arg1 = arguments[1];
330
350
 
package/dist/varstor.js CHANGED
@@ -36,7 +36,7 @@ function isFunction(x) {
36
36
  }
37
37
 
38
38
  function isObject(x) {
39
- return typeof x === "object";
39
+ return Object.prototype.toString.call(x) === "[object Object]";
40
40
  }
41
41
 
42
42
  function isString(x) {
@@ -172,7 +172,7 @@ function getArguments(computedName) {
172
172
  .concat(values);
173
173
  }
174
174
 
175
- function createAccessor(key, value, storageType) {
175
+ function createAccessor(key, storageType) {
176
176
  const accessor = () => STATE[key].value;
177
177
 
178
178
  Object.assign(accessor, {
@@ -257,7 +257,7 @@ function getState(namespace, arg) {
257
257
  }
258
258
 
259
259
  function getNamespaceValues(namespace) {
260
- return (0,_helpers__WEBPACK_IMPORTED_MODULE_1__.getKeys)((0,_namespace__WEBPACK_IMPORTED_MODULE_2__.getByNamespace)(namespace, STATE), "value");
260
+ return recreateStructure((0,_helpers__WEBPACK_IMPORTED_MODULE_1__.getKeys)((0,_namespace__WEBPACK_IMPORTED_MODULE_2__.getByNamespace)(namespace, STATE), "value"));
261
261
  }
262
262
 
263
263
  function getNamespaceAccessors (namespace, cb) {
@@ -302,6 +302,26 @@ function removeStateListener(namespace, observables, cb) {
302
302
  return createStore(namespace());
303
303
  }
304
304
 
305
+ function recreateStructure (value) {
306
+ let newValue = value;
307
+
308
+ if ((0,_helpers__WEBPACK_IMPORTED_MODULE_1__.isArray)(value)) {
309
+ newValue = [];
310
+ value.forEach((v) => newValue.push(recreateStructure(v)));
311
+ return newValue;
312
+ }
313
+
314
+ if ((0,_helpers__WEBPACK_IMPORTED_MODULE_1__.isObject)(value)) {
315
+ newValue = {};
316
+ for (let key in value) {
317
+ newValue[key] = recreateStructure(value[key]);
318
+ }
319
+ return newValue;
320
+ }
321
+
322
+ return newValue;
323
+ }
324
+
305
325
  function main () {
306
326
  const arg1 = arguments[1];
307
327
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "varstor",
3
- "version": "0.2.6",
3
+ "version": "0.3.6",
4
4
  "description": "State manager for web applications and webextensions, employing reactivity, wrapping, and uniting the usage of different storages' values and common variables into a simple universal interface",
5
5
  "license": "MIT",
6
6
  "author": "Igor Morozov <ismorozs@gmail.com>",
package/src/helpers.js CHANGED
@@ -6,7 +6,7 @@ export function isFunction(x) {
6
6
  }
7
7
 
8
8
  export function isObject(x) {
9
- return typeof x === "object";
9
+ return Object.prototype.toString.call(x) === "[object Object]";
10
10
  }
11
11
 
12
12
  export function isString(x) {
package/src/index.js CHANGED
@@ -94,7 +94,7 @@ function getArguments(computedName) {
94
94
  .concat(values);
95
95
  }
96
96
 
97
- function createAccessor(key, value, storageType) {
97
+ function createAccessor(key, storageType) {
98
98
  const accessor = () => STATE[key].value;
99
99
 
100
100
  Object.assign(accessor, {
@@ -179,7 +179,7 @@ function getState(namespace, arg) {
179
179
  }
180
180
 
181
181
  function getNamespaceValues(namespace) {
182
- return getKeys(getByNamespace(namespace, STATE), "value");
182
+ return recreateStructure(getKeys(getByNamespace(namespace, STATE), "value"));
183
183
  }
184
184
 
185
185
  function getNamespaceAccessors (namespace, cb) {
@@ -224,6 +224,26 @@ function removeStateListener(namespace, observables, cb) {
224
224
  return createStore(namespace());
225
225
  }
226
226
 
227
+ function recreateStructure (value) {
228
+ let newValue = value;
229
+
230
+ if (isArray(value)) {
231
+ newValue = [];
232
+ value.forEach((v) => newValue.push(recreateStructure(v)));
233
+ return newValue;
234
+ }
235
+
236
+ if (isObject(value)) {
237
+ newValue = {};
238
+ for (let key in value) {
239
+ newValue[key] = recreateStructure(value[key]);
240
+ }
241
+ return newValue;
242
+ }
243
+
244
+ return newValue;
245
+ }
246
+
227
247
  function main () {
228
248
  const arg1 = arguments[1];
229
249