deep-state-observer
Advanced tools
Comparing version 4.1.12 to 4.1.13
37
bench.js
@@ -30,11 +30,32 @@ const Benchmark = require("benchmark"); | ||
const noProxyNoMaps = new State(getObj(), { useProxy: false, useObjectMaps: false }); | ||
generateSubs(noProxyNoMaps); | ||
const ProxyNoMaps = new State(getObj(), { useProxy: true, useObjectMaps: false }); | ||
generateSubs(ProxyNoMaps); | ||
const noProxyMaps = new State(getObj(), { useProxy: false, useObjectMaps: true }); | ||
generateSubs(noProxyMaps); | ||
const ProxyMaps = new State(getObj(), { useProxy: true, useObjectMaps: true }); | ||
generateSubs(ProxyMaps); | ||
let noProxyNoMaps; | ||
let ProxyNoMaps; | ||
let noProxyMaps; | ||
let ProxyMaps; | ||
new Benchmark.Suite("create") | ||
.add("no proxy no maps", function () { | ||
noProxyNoMaps = new State(getObj(), { useProxy: false, useObjectMaps: false }); | ||
generateSubs(noProxyNoMaps); | ||
}) | ||
.add("proxy no maps", function () { | ||
ProxyNoMaps = new State(getObj(), { useProxy: true, useObjectMaps: false }); | ||
generateSubs(ProxyNoMaps); | ||
}) | ||
.add("no proxy with maps", function () { | ||
noProxyMaps = new State(getObj(), { useProxy: false, useObjectMaps: true }); | ||
generateSubs(noProxyMaps); | ||
}) | ||
.add("proxy & maps", function () { | ||
ProxyMaps = new State(getObj(), { useProxy: true, useObjectMaps: true }); | ||
generateSubs(ProxyMaps); | ||
}) | ||
.on("cycle", function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", function () { | ||
console.log(`Fastest is '${this.filter("fastest").map("name")}'`); | ||
}) | ||
.run(); | ||
console.log("update & get"); | ||
@@ -41,0 +62,0 @@ new Benchmark.Suite("update get") |
@@ -33,3 +33,3 @@ const State = require("./index.cjs.js"); | ||
const data = prepareData(); | ||
const state = new State(data, { useObjectMap: false, useProxy: false }); | ||
const state = new State(data, { useObjectMap: true, useProxy: false }); | ||
@@ -104,3 +104,3 @@ console.log("Data generated.", Object.keys(data.nested.values.basic.data).length); | ||
const time = { start: Date.now() }; | ||
state.update(`nested.*.basic.data.${Math.round(Math.random() * dataItemsCount)}.value`, () => i + " mod"); | ||
state.update(`nested.values.basic.data.${Math.round(Math.random() * dataItemsCount)}.value`, () => i + " mod"); | ||
time.end = Date.now(); | ||
@@ -107,0 +107,0 @@ time.result = time.end - time.start; |
@@ -196,3 +196,2 @@ export interface PathInfo { | ||
private updateMapDown; | ||
private deleteMapReferences; | ||
private pathGet; | ||
@@ -199,0 +198,0 @@ private pathSet; |
25
index.ts
@@ -255,3 +255,3 @@ import WildcardObject from "./wildcard-object-scan"; | ||
useObjectMaps: true, | ||
useProxy: true, | ||
useProxy: false, | ||
maxSimultaneousJobs: 1000, | ||
@@ -353,3 +353,7 @@ maxQueueRuns: 1000, | ||
const path = obj[this.proxyProperty].path ? obj[this.proxyProperty].path + this.options.delimiter + prop : prop; | ||
obj[prop] = this.updateMapDown(path, value, obj); | ||
if (!this.isSaving(this.split(path), obj)) { | ||
obj[prop] = this.updateMapDown(path, value, obj); | ||
} else { | ||
obj[prop] = value; | ||
} | ||
return true; | ||
@@ -380,3 +384,5 @@ }, | ||
// updateMapDown will check if we are using proxy or not | ||
this.setNodeSaving(this.rootProxyNode, ""); | ||
this.data = this.updateMapDown("", data, this.rootProxyNode, false); | ||
this.unsetNodeSaving(this.rootProxyNode, ""); | ||
} else if (this.options.useProxy) { | ||
@@ -417,3 +423,2 @@ this.data = this.makeObservable(data, "", this.rootProxyNode); | ||
for (const key of map.keys()) { | ||
if (key === this.proxyProperty) continue; | ||
if (key.startsWith(fullPath)) map.delete(key); | ||
@@ -462,9 +467,2 @@ } | ||
private deleteMapReferences(path: string) { | ||
if (!this.options.useObjectMaps) return; | ||
for (const key of this.map.keys()) { | ||
if (key.startsWith(path)) this.map.delete(key); | ||
} | ||
} | ||
private pathGet(path: string) { | ||
@@ -506,3 +504,3 @@ if (!this.options.useObjectMaps) return Path.get(this.split(path), this.data); | ||
if (!referencesDeleted) { | ||
this.deleteMapReferences(currentPath); | ||
this.deleteFromMap(currentPath); | ||
referencesDeleted = true; | ||
@@ -525,5 +523,3 @@ } | ||
} | ||
if (!parent) { | ||
console.log("pathSet", pathChunks, obj, this.rootProxyNode, this.data); | ||
} | ||
if (this.options.useProxy) { | ||
@@ -1330,2 +1326,3 @@ // NOTICE: we are using objectMaps because this method is fired otherwise it is replaced by object traverse pathSet | ||
: new WildcardObject(newValue, this.options.delimiter, this.options.wildcard).get(restBelowPathCut); | ||
restBelowValues[restBelowPathCut] = wildcardNewValues; | ||
@@ -1332,0 +1329,0 @@ const params = listenersCollection.paramsInfo |
{ | ||
"name": "deep-state-observer", | ||
"version": "4.1.12", | ||
"version": "4.1.13", | ||
"description": "Deep state observer is an state management library that will fire listeners only when specified object node (which also can be a wildcard) was changed.", | ||
@@ -5,0 +5,0 @@ "main": "index.cjs.js", |
@@ -152,2 +152,3 @@ "use strict"; | ||
var pathDelimitersCount = this.getIndicesCount(this.delimiter, path); | ||
var len = path.length; | ||
try { | ||
@@ -154,0 +155,0 @@ for (var _b = __values(this.objectMap), _c = _b.next(); !_c.done; _c = _b.next()) { |
@@ -131,2 +131,3 @@ import { Match } from "./stringMatcher"; | ||
const pathDelimitersCount = this.getIndicesCount(this.delimiter, path); | ||
const len = path.length; | ||
for (const [key, value] of this.objectMap) { | ||
@@ -133,0 +134,0 @@ if (this.getIndicesCount(this.delimiter, key) === pathDelimitersCount && this.match(path, key)) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
641673
15593