deep-state-observer
Advanced tools
Comparing version 4.1.8 to 4.1.9
21
index.ts
@@ -342,14 +342,14 @@ import WildcardObject from "./wildcard-object-scan"; | ||
this.options = { ...getDefaultOptions(), ...options }; | ||
//if (this.options.useProxy) this.options.useObjectMaps = true; | ||
if (this.options.useProxy) { | ||
if (this.options.useObjectMaps) { | ||
this.data = this.updateMapDown("", data, this.rootProxyNode, false); | ||
} else { | ||
this.data = this.makeObservable(data, "", this.rootProxyNode); | ||
} | ||
this.proxy = this.data; | ||
this.$$$ = this.proxy; | ||
} else { | ||
if (this.options.useObjectMaps) { | ||
this.data = this.updateMapDown("", data, this.rootProxyNode, false); | ||
} | ||
if (this.options.useProxy && !this.options.useObjectMaps) { | ||
this.data = this.makeObservable(data, "", this.rootProxyNode); | ||
} | ||
if (!this.options.useObjectMaps && !this.options.useProxy) { | ||
this.data = data; | ||
} | ||
this.proxy = this.data; | ||
this.$$$ = this.proxy; | ||
@@ -419,2 +419,3 @@ this.id = 0; | ||
if (!this.options.useObjectMaps) return Path.get(this.split(path), this.data); | ||
if (!path) return this.data; | ||
return this.map.get(path); | ||
@@ -421,0 +422,0 @@ } |
{ | ||
"name": "deep-state-observer", | ||
"version": "4.1.8", | ||
"version": "4.1.9", | ||
"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", |
@@ -308,2 +308,26 @@ const State = require("../index.cjs.js"); | ||
it("should update root node (only maps)", () => { | ||
const state = new State({ x: { y: { z: 1 } } }, { useObjectMaps: true, useProxy: false }); | ||
const values = []; | ||
state.subscribe("x.y.z", (val) => { | ||
values.push(val); | ||
}); | ||
expect(values[0]).toEqual(1); | ||
state.update("", (oldValue) => { | ||
return { x: oldValue.x, xx: { yy: { zz: 1 } } }; | ||
}); | ||
expect(state.data.xx.yy.zz).toEqual(1); | ||
expect(state.data[undefined]).toBeFalsy(); | ||
expect(state.get("x.y.z")).toEqual(1); | ||
expect(state.get("xx.yy.zz")).toEqual(1); | ||
state.update("yy.zz", 22); | ||
expect(state.get("yy.zz")).toEqual(22); | ||
expect(state.data.yy.zz).toEqual(22); | ||
state.collect(); | ||
state.multi(true).update("e.as", "as").update("e.tu", "tu").done(); | ||
state.executeCollected(); | ||
expect(state.data.e.as).toEqual("as"); | ||
expect(state.data.e.tu).toEqual("tu"); | ||
}); | ||
it("should save function", () => { | ||
@@ -310,0 +334,0 @@ const values = []; |
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
607642
14862