Socket
Socket
Sign inDemoInstall

deep-state-observer

Package Overview
Dependencies
Maintainers
1
Versions
225
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-state-observer - npm Package Compare versions

Comparing version 5.5.4 to 5.5.5

15

index.ts

@@ -860,3 +860,6 @@ import WildcardObject from "./wildcard-object-scan";

this.subscribeQueue.push(() => {
singleListener.listener.fn(singleListener.value(), singleListener.eventInfo);
singleListener.listener.fn(
singleListener.value ? singleListener.value() : undefined,
singleListener.eventInfo
);
});

@@ -874,3 +877,6 @@ } else {

fn: () => {
singleListener.listener.fn(singleListener.value(), singleListener.eventInfo);
singleListener.listener.fn(
singleListener.value ? singleListener.value() : undefined,
singleListener.eventInfo
);
},

@@ -897,3 +903,3 @@ options: singleListener.listener.options,

for (const bulk of bulkListener.value) {
bulkValue.push({ ...bulk, value: bulk.value() });
bulkValue.push({ ...bulk, value: bulk.value ? bulk.value() : undefined });
}

@@ -1050,3 +1056,4 @@ if (!this.isMuted(bulkListener.listener.fn)) {

for (const [listenerId, listener] of listenersCollection.listeners) {
if (listener.options.bulkValue) return true;
if (listener.options.bulk && listener.options.bulkValue) return true;
if (!listener.options.bulk) return true;
}

@@ -1053,0 +1060,0 @@ return false;

{
"name": "deep-state-observer",
"version": "5.5.4",
"version": "5.5.5",
"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",

@@ -1,48 +0,44 @@

const State = require('../index.cjs.js');
const path = require('path');
const fs = require('fs');
const State = require("../index.cjs.js");
const path = require("path");
const fs = require("fs");
describe('State', () => {
it('should match simple wildcards', () => {
describe("State", () => {
it("should match simple wildcards", () => {
const state = new State({});
expect(state.match('te*t', 'test')).toEqual(true);
expect(state.match('*est', 'test')).toEqual(true);
expect(state.match('te*', 'test')).toEqual(true);
expect(state.match('*', 'test')).toEqual(true);
expect(state.match('*', '')).toEqual(true);
expect(state.match("te*t", "test")).toEqual(true);
expect(state.match("*est", "test")).toEqual(true);
expect(state.match("te*", "test")).toEqual(true);
expect(state.match("*", "test")).toEqual(true);
expect(state.match("*", "")).toEqual(true);
expect(state.match('', 'test')).toEqual(false);
expect(state.match('xy*', 'test')).toEqual(false);
expect(state.match('*xy', 'test')).toEqual(false);
expect(state.match("", "test")).toEqual(false);
expect(state.match("xy*", "test")).toEqual(false);
expect(state.match("*xy", "test")).toEqual(false);
expect(
state.match('one.two.three.*.five', 'one.two.three.four.five')
).toEqual(true);
expect(state.match('one.two.three.*.five', 'one.two.three.four')).toEqual(
false
);
expect(state.match("one.two.three.*.five", "one.two.three.four.five")).toEqual(true);
expect(state.match("one.two.three.*.five", "one.two.three.four")).toEqual(false);
});
it('should check existence of methods and data', () => {
const state = new State({ test: '123' });
expect(typeof state).toEqual('object');
expect(typeof state.subscribe).toBe('function');
expect(typeof state.subscribeAll).toBe('function');
expect(typeof state.update).toBe('function');
expect(typeof state.get).toBe('function');
expect(typeof state.destroy).toBe('function');
it("should check existence of methods and data", () => {
const state = new State({ test: "123" });
expect(typeof state).toEqual("object");
expect(typeof state.subscribe).toBe("function");
expect(typeof state.subscribeAll).toBe("function");
expect(typeof state.update).toBe("function");
expect(typeof state.get).toBe("function");
expect(typeof state.destroy).toBe("function");
state.destroy();
});
it('should call State', () => {
const state = new State({ a: 'a', b: 'b', c: { d: 'd' } });
it("should call State", () => {
const state = new State({ a: "a", b: "b", c: { d: "d" } });
let $d;
state.subscribe('c.d', (d) => {
state.subscribe("c.d", (d) => {
$d = d;
});
expect($d).toEqual('d');
expect($d).toEqual("d");
state.destroy();
});
it('should update and watch', () => {
it("should update and watch", () => {
const state = new State({

@@ -55,3 +51,3 @@ test: {

let event = 0;
state.subscribe('test.test2', (value) => {
state.subscribe("test.test2", (value) => {
test2 = value;

@@ -66,3 +62,3 @@ if (event === 0) {

expect(test2).toEqual(123);
state.update('test.test2', (oldValue) => {
state.update("test.test2", (oldValue) => {
return 100;

@@ -74,40 +70,40 @@ });

it('should notify nested subscribers about change', () => {
it("should notify nested subscribers about change", () => {
const state = new State({
one: { two: { three: { four: 'go!' } } },
one: { two: { three: { four: "go!" } } },
});
const paths = [];
const values = [];
state.subscribe('one.two.three.four', (value, eventInfo) => {
state.subscribe("one.two.three.four", (value, eventInfo) => {
values.push(value);
paths.push(eventInfo.path.resolved);
});
expect(paths[0]).toEqual('one.two.three.four');
expect(values[0]).toEqual('go!');
expect(paths[0]).toEqual("one.two.three.four");
expect(values[0]).toEqual("go!");
state.update('one', { two: { three: { four: 'modified' } } });
expect(paths[1]).toEqual('one.two.three.four');
expect(values[1]).toEqual('modified');
state.update("one", { two: { three: { four: "modified" } } });
expect(paths[1]).toEqual("one.two.three.four");
expect(values[1]).toEqual("modified");
});
it('should watch all paths', () => {
it("should watch all paths", () => {
const state = new State({ x: 10, y: 20, z: { xyz: 50 } });
let result = {};
const paths = [];
state.subscribeAll(['x', 'y', 'z.xyz'], (value, eventInfo) => {
state.subscribeAll(["x", "y", "z.xyz"], (value, eventInfo) => {
paths.push(eventInfo.path.resolved);
});
expect(paths).toEqual(['x', 'y', 'z.xyz']);
expect(paths).toEqual(["x", "y", "z.xyz"]);
state.destroy();
});
it('should accept value instead of function inside update', () => {
it("should accept value instead of function inside update", () => {
const state = new State({ x: 10, y: 20, z: { xyz: 50 } });
expect(state.get()).toEqual({ x: 10, y: 20, z: { xyz: 50 } });
state.update('z.xyz', 'string instead of fn');
expect(state.get('z.xyz')).toEqual('string instead of fn');
state.update("z.xyz", "string instead of fn");
expect(state.get("z.xyz")).toEqual("string instead of fn");
state.destroy();
});
it('should match wildcards (object)', () => {
it("should match wildcards (object)", () => {
const state = new State({

@@ -121,7 +117,7 @@ one: {

const values = [];
state.subscribe('one.*.three', (value, eventInfo) => {
state.subscribe("one.*.three", (value, eventInfo) => {
paths.push(eventInfo.path.resolved); // 2
values.push(value);
});
state.subscribe('one.*.*.four.*', (value, eventInfo) => {
state.subscribe("one.*.*.four.*", (value, eventInfo) => {
paths.push(eventInfo.path.resolved); // 3

@@ -139,31 +135,25 @@ values.push(value);

const fullPath = 'one.two.three.four.five';
state.update(fullPath, 'mod');
const fullPath = "one.two.three.four.five";
state.update(fullPath, "mod");
expect(paths.length).toEqual(7);
expect(values.length).toEqual(7);
expect(values[5]).toEqual({ four: { five: 'mod' } });
expect(values[6]).toEqual('mod');
expect(values[5]).toEqual({ four: { five: "mod" } });
expect(values[6]).toEqual("mod");
});
it('should match wildcards (array)', () => {
it("should match wildcards (array)", () => {
const state = new State({
one: [
{ two: 2 },
{ two: 22 },
{ two: 222 },
{ three: 3 },
[{ test: 'x' }],
],
one: [{ two: 2 }, { two: 22 }, { two: 222 }, { three: 3 }, [{ test: "x" }]],
});
const paths = [];
const values = [];
state.subscribe('one.*.two', (value, eventInfo) => {
state.subscribe("one.*.two", (value, eventInfo) => {
paths.push(eventInfo.path.resolved); // 3
values.push(value);
});
state.subscribe('one.*.*.test', (value, eventInfo) => {
state.subscribe("one.*.*.test", (value, eventInfo) => {
paths.push(eventInfo.path.resolved); // 1
values.push(value);
});
state.subscribe('one.*.three', (value, eventInfo) => {
state.subscribe("one.*.three", (value, eventInfo) => {
paths.push(eventInfo.path.resolved); // 1

@@ -178,17 +168,17 @@ values.push(value);

expect(values[3]).toEqual('x');
expect(values[3]).toEqual("x");
expect(values[4]).toEqual(3);
const fullPath = 'one.0.two';
state.update(fullPath, 'mod');
const fullPath = "one.0.two";
state.update(fullPath, "mod");
expect(paths.length).toEqual(6);
expect(values.length).toEqual(6);
expect(values[5]).toEqual('mod');
expect(values[5]).toEqual("mod");
});
it('should watch recursively', () => {
it("should watch recursively", () => {
const state = new State({ one: { two: { three: 3 }, 2: 2 } });
const paths = [];
const values = [];
state.subscribe('one', (value, eventInfo) => {
state.subscribe("one", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);

@@ -199,17 +189,17 @@ values.push(value);

expect(values.length).toEqual(1);
expect(paths[0]).toEqual('one');
expect(paths[0]).toEqual("one");
expect(values[0]).toEqual({ two: { three: 3 }, 2: 2 });
state.update('one.two.three', 33);
state.update("one.two.three", 33);
expect(paths.length).toEqual(2);
expect(values.length).toEqual(2);
expect(paths[1]).toEqual('one.two.three');
expect(paths[1]).toEqual("one.two.three");
expect(values[1]).toEqual({ two: { three: 33 }, 2: 2 });
});
it('should watch recursively within path (subscribe)', () => {
it("should watch recursively within path (subscribe)", () => {
const state = new State({ one: { two: { three: { four: 4 } }, 2: 2 } });
const paths = [];
const values = [];
state.subscribe('one.two.three', (value, eventInfo) => {
state.subscribe("one.two.three", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);

@@ -220,13 +210,13 @@ values.push(value);

expect(values.length).toEqual(1);
expect(paths[0]).toEqual('one.two.three');
expect(paths[0]).toEqual("one.two.three");
expect(values[0]).toEqual({ four: 4 });
state.update('one.two.three', { four: 44 });
state.update("one.two.three", { four: 44 });
expect(paths.length).toEqual(2);
expect(values.length).toEqual(2);
expect(paths[1]).toEqual('one.two.three');
expect(paths[1]).toEqual("one.two.three");
expect(values[1]).toEqual({ four: 44 });
});
it('should watch recursively within path (subscribeAll)', () => {
it("should watch recursively within path (subscribeAll)", () => {
const state = new State({

@@ -237,3 +227,3 @@ one: { two: { three: { four: [{ x: 1 }, { y: 2 }, { z: 3 }] } }, 2: 2 },

const values = [];
state.subscribeAll(['one.two.three.four.0'], (value, eventInfo) => {
state.subscribeAll(["one.two.three.four.0"], (value, eventInfo) => {
paths.push(eventInfo.path.resolved);

@@ -244,13 +234,13 @@ values.push(value);

expect(values.length).toEqual(1);
expect(paths[0]).toEqual('one.two.three.four.0');
expect(paths[0]).toEqual("one.two.three.four.0");
expect(values[0]).toEqual({ x: 1 });
state.update('one.two.three.four', [{ x: 2 }, { y: 2 }, { z: 3 }]);
state.update("one.two.three.four", [{ x: 2 }, { y: 2 }, { z: 3 }]);
expect(paths.length).toEqual(2);
expect(values.length).toEqual(2);
expect(paths[1]).toEqual('one.two.three.four.0');
expect(paths[1]).toEqual("one.two.three.four.0");
expect(values[1]).toEqual({ x: 2 });
});
it('should watch recursively within path and return final value if it is not an object/array', () => {
it("should watch recursively within path and return final value if it is not an object/array", () => {
const state = new State({

@@ -261,3 +251,3 @@ one: { two: { three: { four: [{ x: 1 }, { y: 2 }, { z: 3 }] } }, 2: 2 },

const values = [];
state.subscribeAll(['one.two.three.four.0.x'], (value, eventInfo) => {
state.subscribeAll(["one.two.three.four.0.x"], (value, eventInfo) => {
paths.push(eventInfo.path.resolved);

@@ -268,13 +258,13 @@ values.push(value);

expect(values.length).toEqual(1);
expect(paths[0]).toEqual('one.two.three.four.0.x');
expect(paths[0]).toEqual("one.two.three.four.0.x");
expect(values[0]).toEqual(1);
state.update('one.two.three.four', [{ x: 2 }, { y: 2 }, { z: 3 }]);
state.update("one.two.three.four", [{ x: 2 }, { y: 2 }, { z: 3 }]);
expect(paths.length).toEqual(2);
expect(values.length).toEqual(2);
expect(paths[1]).toEqual('one.two.three.four.0.x');
expect(paths[1]).toEqual("one.two.three.four.0.x");
expect(values[1]).toEqual(2);
});
it('should watch recursively within object with numeric values', () => {
it("should watch recursively within object with numeric values", () => {
const state = new State({

@@ -291,3 +281,3 @@ one: {

const values = [];
state.subscribeAll(['one.two'], (value, eventInfo) => {
state.subscribeAll(["one.two"], (value, eventInfo) => {
paths.push(eventInfo.path.resolved);

@@ -298,3 +288,3 @@ values.push(value);

expect(values.length).toEqual(1);
expect(paths[0]).toEqual('one.two');
expect(paths[0]).toEqual("one.two");
expect(values[0]).toEqual({

@@ -306,6 +296,6 @@ 1: { x: 1 },

state.update('one.two.2.x', 22);
state.update("one.two.2.x", 22);
expect(paths.length).toEqual(2);
expect(values.length).toEqual(2);
expect(paths[1]).toEqual('one.two.2.x');
expect(paths[1]).toEqual("one.two.2.x");
expect(values[1]).toEqual({

@@ -318,5 +308,5 @@ 1: { x: 1 },

it('should match simple params', () => {
it("should match simple params", () => {
const state = new State({
users: { 1: { name: 'john', age: 35 }, 2: { name: 'alice', age: 30 } },
users: { 1: { name: "john", age: 35 }, 2: { name: "alice", age: 30 } },
});

@@ -326,3 +316,3 @@ const paths = [];

const params = [];
state.subscribe('users.:id.name', (value, eventInfo) => {
state.subscribe("users.:id.name", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);

@@ -333,16 +323,16 @@ values.push(value);

expect(paths.length).toEqual(2);
expect(paths[0]).toEqual('users.1.name');
expect(paths[1]).toEqual('users.2.name');
expect(values[0]).toEqual('john');
expect(values[1]).toEqual('alice');
expect(paths[0]).toEqual("users.1.name");
expect(paths[1]).toEqual("users.2.name");
expect(values[0]).toEqual("john");
expect(values[1]).toEqual("alice");
state.update('users.1.name', 'madmax');
state.update("users.1.name", "madmax");
expect(paths.length).toEqual(3);
expect(paths[2]).toEqual('users.1.name');
expect(values[2]).toEqual('madmax');
expect(paths[2]).toEqual("users.1.name");
expect(values[2]).toEqual("madmax");
});
it('should match simple params and return bulk value', () => {
it("should match simple params and return bulk value", () => {
const state = new State({
users: { 1: { name: 'john', age: 35 }, 2: { name: 'alice', age: 30 } },
users: { 1: { name: "john", age: 35 }, 2: { name: "alice", age: 30 } },
});

@@ -353,3 +343,3 @@ const paths = [];

state.subscribe(
'users.:id.name',
"users.:id.name",
(bulk, eventInfo) => {

@@ -365,14 +355,14 @@ bulk.forEach((item) => {

expect(paths.length).toEqual(2);
expect(paths[0]).toEqual('users.1.name');
expect(paths[1]).toEqual('users.2.name');
expect(values[0]).toEqual('john');
expect(values[1]).toEqual('alice');
expect(paths[0]).toEqual("users.1.name");
expect(paths[1]).toEqual("users.2.name");
expect(values[0]).toEqual("john");
expect(values[1]).toEqual("alice");
state.update('users.1.name', 'madmax');
state.update("users.1.name", "madmax");
expect(paths.length).toEqual(3);
expect(paths[2]).toEqual('users.1.name');
expect(values[2]).toEqual('madmax');
expect(paths[2]).toEqual("users.1.name");
expect(values[2]).toEqual("madmax");
});
it('should update proper leaf', () => {
it("should update proper leaf", () => {
const state = new State({

@@ -382,5 +372,5 @@ config: {

rows: {
1: { id: 'id-1' },
2: { id: 'id-2' },
3: { id: 'id-3' },
1: { id: "id-1" },
2: { id: "id-2" },
3: { id: "id-3" },
},

@@ -392,5 +382,5 @@ },

rows: {
1: { id: 'id-1' },
2: { id: 'id-2' },
3: { id: 'id-3' },
1: { id: "id-1" },
2: { id: "id-2" },
3: { id: "id-3" },
},

@@ -402,10 +392,10 @@ },

const values = [];
state.subscribe('config.list.rows', (value, eventInfo) => {
state.subscribe("config.list.rows", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);
state.update('internal.list.rows', { ...value });
state.update("internal.list.rows", { ...value });
});
expect(paths[0]).toEqual('config.list.rows');
expect(paths[0]).toEqual("config.list.rows");
});
it('should bulk wildcarded subscribeAll', () => {
it("should bulk wildcarded subscribeAll", () => {
const state = new State({

@@ -416,3 +406,3 @@ something: [{ x: 1 }, { x: 1 }, { x: 1 }, { x: 1 }],

state.subscribeAll(
['something', 'something.*.x'],
["something", "something.*.x"],
(bulk) => {

@@ -424,7 +414,7 @@ count++;

expect(count).toEqual(2);
state.update('something', [...state.get('something'), { x: 'added' }]);
state.update("something", [...state.get("something"), { x: "added" }]);
expect(count).toEqual(4);
});
it('should update values from wildcard path', () => {
it("should update values from wildcard path", () => {
const state = new State({

@@ -435,3 +425,3 @@ one: { two: { three: { four: { five: 5 } } } },

const values = [];
state.subscribe('one.*.three.four.five', (value, eventInfo) => {
state.subscribe("one.*.three.four.five", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);

@@ -441,23 +431,23 @@ values.push(value);

expect(paths.length).toEqual(1);
expect(paths[0]).toEqual('one.two.three.four.five');
expect(paths[0]).toEqual("one.two.three.four.five");
expect(values[0]).toEqual(5);
state.update('one.two.*.four.five', 55);
state.update("one.two.*.four.five", 55);
expect(paths.length).toEqual(2);
expect(paths[1]).toEqual('one.two.three.four.five');
expect(state.get('one.two.three.four.five')).toEqual(55);
expect(paths[1]).toEqual("one.two.three.four.five");
expect(state.get("one.two.three.four.five")).toEqual(55);
expect(values[1]).toEqual(55);
state.update('one.two.*.four.five', 555);
expect(paths[2]).toEqual('one.two.three.four.five');
state.update("one.two.*.four.five", 555);
expect(paths[2]).toEqual("one.two.three.four.five");
expect(values[2]).toEqual(555);
expect(state.get('one.two.three.four.five')).toEqual(555);
expect(state.get("one.two.three.four.five")).toEqual(555);
state.update('*.two.*.four.five', 5555);
expect(paths[3]).toEqual('one.two.three.four.five');
state.update("*.two.*.four.five", 5555);
expect(paths[3]).toEqual("one.two.three.four.five");
expect(values[3]).toEqual(5555);
expect(state.get('one.two.three.four.five')).toEqual(5555);
expect(state.get("one.two.three.four.five")).toEqual(5555);
});
it('should not listen to recursive changes', () => {
it("should not listen to recursive changes", () => {
const state = new State({

@@ -468,27 +458,27 @@ one: { two: { three: { four: { five: 5 } } } },

const values = [];
state.subscribe('one.*.three;', (value, eventInfo) => {
state.subscribe("one.*.three;", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);
values.push(value);
});
expect(paths[0]).toEqual('one.two.three');
expect(paths[0]).toEqual("one.two.three");
expect(values[0]).toEqual({ four: { five: 5 } });
state.update('one.two.*.four.five', 55);
state.update("one.two.*.four.five", 55);
expect(paths.length).toEqual(1);
expect(values.length).toEqual(1);
expect(state.get('one.two.three.four.five')).toEqual(55);
expect(state.get("one.two.three.four.five")).toEqual(55);
state.update('one.two.*', { four: { five: 555 } });
state.update("one.two.*", { four: { five: 555 } });
expect(paths.length).toEqual(2);
expect(paths[1]).toEqual('one.two.three');
expect(paths[1]).toEqual("one.two.three");
expect(values[1]).toEqual({ four: { five: 555 } });
expect(state.get('one.two.three.four.five')).toEqual(555);
expect(state.get("one.two.three.four.five")).toEqual(555);
state.update('*.two.*.four.five', 5555);
state.update("*.two.*.four.five", 5555);
expect(paths.length).toEqual(2);
expect(values.length).toEqual(2);
expect(state.get('one.two.three.four.five')).toEqual(5555);
expect(state.get("one.two.three.four.five")).toEqual(5555);
});
it('should update values from wildcard path (children)', () => {
it("should update values from wildcard path (children)", () => {
const state = new State({

@@ -499,26 +489,26 @@ one: { two: { three: { four: { five: 5 } } } },

const values = [];
state.subscribe('one.*.three.four.five', (value, eventInfo) => {
state.subscribe("one.*.three.four.five", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);
values.push(value);
});
expect(paths[0]).toEqual('one.two.three.four.five');
expect(paths[0]).toEqual("one.two.three.four.five");
expect(values[0]).toEqual(5);
state.update('one.two.*.four', { five: 55 });
expect(paths[1]).toEqual('one.two.three.four.five');
state.update("one.two.*.four", { five: 55 });
expect(paths[1]).toEqual("one.two.three.four.five");
expect(values[1]).toEqual(55);
expect(state.get('one.two.three.four.five')).toEqual(55);
expect(state.get("one.two.three.four.five")).toEqual(55);
state.update('one.two.*.four', { five: 555 });
expect(paths[2]).toEqual('one.two.three.four.five');
state.update("one.two.*.four", { five: 555 });
expect(paths[2]).toEqual("one.two.three.four.five");
expect(values[2]).toEqual(555);
expect(state.get('one.two.three.four.five')).toEqual(555);
expect(state.get("one.two.three.four.five")).toEqual(555);
state.update('*.two.*.four', { five: 5555 });
expect(paths[3]).toEqual('one.two.three.four.five');
state.update("*.two.*.four", { five: 5555 });
expect(paths[3]).toEqual("one.two.three.four.five");
expect(values[3]).toEqual(5555);
expect(state.get('one.two.three.four.five')).toEqual(5555);
expect(state.get("one.two.three.four.five")).toEqual(5555);
});
it('should update values from wildcard path (recursive)', () => {
it("should update values from wildcard path (recursive)", () => {
const state = new State({

@@ -529,26 +519,26 @@ one: { two: { three: { four: { five: 5 } } } },

const values = [];
state.subscribe('one.two.three.four', (value, eventInfo) => {
state.subscribe("one.two.three.four", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);
values.push(value);
});
expect(paths[0]).toEqual('one.two.three.four');
expect(paths[0]).toEqual("one.two.three.four");
expect(values[0]).toEqual({ five: 5 });
state.update('one.two.*.four.five', 55);
expect(paths[1]).toEqual('one.two.three.four.five');
state.update("one.two.*.four.five", 55);
expect(paths[1]).toEqual("one.two.three.four.five");
expect(values[1]).toEqual({ five: 55 });
expect(state.get('one.two.three.four.five')).toEqual(55);
expect(state.get("one.two.three.four.five")).toEqual(55);
state.update('one.two.*.four.five', 555);
expect(paths[2]).toEqual('one.two.three.four.five');
state.update("one.two.*.four.five", 555);
expect(paths[2]).toEqual("one.two.three.four.five");
expect(values[2]).toEqual({ five: 555 });
expect(state.get('one.two.three.four.five')).toEqual(555);
expect(state.get("one.two.three.four.five")).toEqual(555);
state.update('*.two.*.four.five', 5555);
expect(paths[3]).toEqual('one.two.three.four.five');
state.update("*.two.*.four.five", 5555);
expect(paths[3]).toEqual("one.two.three.four.five");
expect(values[3]).toEqual({ five: 5555 });
expect(state.get('one.two.three.four.five')).toEqual(5555);
expect(state.get("one.two.three.four.five")).toEqual(5555);
});
it('should update values from wildcard path (recursive & wildcard)', () => {
it("should update values from wildcard path (recursive & wildcard)", () => {
const state = new State({

@@ -559,26 +549,26 @@ one: { two: { three: { four: { five: 5 } } } },

const values = [];
state.subscribe('one.*.three.four', (value, eventInfo) => {
state.subscribe("one.*.three.four", (value, eventInfo) => {
paths.push(eventInfo.path.resolved);
values.push(value);
});
expect(paths[0]).toEqual('one.two.three.four');
expect(paths[0]).toEqual("one.two.three.four");
expect(values[0]).toEqual({ five: 5 });
state.update('one.two.*.four.five', 55);
expect(paths[1]).toEqual('one.two.three.four.five');
state.update("one.two.*.four.five", 55);
expect(paths[1]).toEqual("one.two.three.four.five");
expect(values[1]).toEqual({ five: 55 });
expect(state.get('one.two.three.four.five')).toEqual(55);
expect(state.get("one.two.three.four.five")).toEqual(55);
state.update('one.two.*.four.five', 555);
expect(paths[2]).toEqual('one.two.three.four.five');
state.update("one.two.*.four.five", 555);
expect(paths[2]).toEqual("one.two.three.four.five");
expect(values[2]).toEqual({ five: 555 });
expect(state.get('one.two.three.four.five')).toEqual(555);
expect(state.get("one.two.three.four.five")).toEqual(555);
state.update('*.two.*.four.five', 5555);
expect(paths[3]).toEqual('one.two.three.four.five');
state.update("*.two.*.four.five", 5555);
expect(paths[3]).toEqual("one.two.three.four.five");
expect(values[3]).toEqual({ five: 5555 });
expect(state.get('one.two.three.four.five')).toEqual(5555);
expect(state.get("one.two.three.four.five")).toEqual(5555);
});
it('should notify only specified strict listeners', () => {
it("should notify only specified strict listeners", () => {
const state = new State({

@@ -589,7 +579,7 @@ one: { two: { three: 3 } },

const paths = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);
paths.push(eventInfo.path.resolved);
});
state.subscribe('one.two.three', (val, eventInfo) => {
state.subscribe("one.two.three", (val, eventInfo) => {
values.push(val);

@@ -599,10 +589,10 @@ paths.push(eventInfo.path.resolved);

expect(values.length).toEqual(2);
state.update('one.two', { three: 33 }, { only: ['three'] });
state.update("one.two", { three: 33 }, { only: ["three"] });
expect(paths.length).toEqual(3);
expect(values[2]).toEqual(33);
expect(paths[2]).toEqual('one.two.three');
expect(state.get('one.two.three')).toEqual(33);
expect(paths[2]).toEqual("one.two.three");
expect(state.get("one.two.three")).toEqual(33);
});
it('should notify only specified strict listeners #2', () => {
it("should notify only specified strict listeners #2", () => {
const state = new State({

@@ -613,7 +603,7 @@ one: { two: { three: { four: { five: 5 } } } },

const paths = [];
state.subscribe('one.two.*.four', (val, eventInfo) => {
state.subscribe("one.two.*.four", (val, eventInfo) => {
values.push(val);
paths.push(eventInfo.path.resolved);
});
state.subscribe('one.two.three.*.five', (val, eventInfo) => {
state.subscribe("one.two.three.*.five", (val, eventInfo) => {
values.push(val);

@@ -624,3 +614,3 @@ paths.push(eventInfo.path.resolved);

state.update(
'one.two.three',
"one.two.three",
function three(value) {

@@ -630,11 +620,11 @@ value.four = { five: 55 };

},
{ only: ['four'] }
{ only: ["four"] }
);
expect(paths.length).toEqual(3);
expect(values[2]).toEqual({ five: 55 });
expect(paths[2]).toEqual('one.two.three.four');
expect(state.get('one.two.three.four.five')).toEqual(55);
expect(paths[2]).toEqual("one.two.three.four");
expect(state.get("one.two.three.four.five")).toEqual(55);
});
it('should notify only specified strict listeners (nested)', () => {
it("should notify only specified strict listeners (nested)", () => {
const state = new State({

@@ -645,7 +635,7 @@ one: { two: { three: { four: 4 } } },

const paths = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);
paths.push(eventInfo.path.resolved);
});
state.subscribe('one.two.three.four', (val, eventInfo) => {
state.subscribe("one.two.three.four", (val, eventInfo) => {
values.push(val);

@@ -655,10 +645,10 @@ paths.push(eventInfo.path.resolved);

expect(values.length).toEqual(2);
state.update('one.two', { three: { four: 44 } }, { only: ['three.four'] });
state.update("one.two", { three: { four: 44 } }, { only: ["three.four"] });
expect(paths.length).toEqual(3);
expect(values[2]).toEqual(44);
expect(paths[2]).toEqual('one.two.three.four');
expect(state.get('one.two.three.four')).toEqual(44);
expect(paths[2]).toEqual("one.two.three.four");
expect(state.get("one.two.three.four")).toEqual(44);
});
it('should notify only specified strict listeners (nested & wildcard)', () => {
it("should notify only specified strict listeners (nested & wildcard)", () => {
const state = new State({

@@ -669,7 +659,7 @@ one: { two: { three: { four: 4 } } },

const paths = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);
paths.push(eventInfo.path.resolved);
});
state.subscribe('one.two.three.four', (val, eventInfo) => {
state.subscribe("one.two.three.four", (val, eventInfo) => {
values.push(val);

@@ -679,10 +669,10 @@ paths.push(eventInfo.path.resolved);

expect(values.length).toEqual(2);
state.update('one.two', { three: { four: 44 } }, { only: ['*.four'] });
state.update("one.two", { three: { four: 44 } }, { only: ["*.four"] });
expect(paths.length).toEqual(3);
expect(values[2]).toEqual(44);
expect(paths[2]).toEqual('one.two.three.four');
expect(state.get('one.two.three.four')).toEqual(44);
expect(paths[2]).toEqual("one.two.three.four");
expect(state.get("one.two.three.four")).toEqual(44);
});
it('should notify only specified strict listeners (nested & wildcard 2)', () => {
it("should notify only specified strict listeners (nested & wildcard 2)", () => {
const state = new State({

@@ -693,7 +683,7 @@ one: { two: { three: { four: 4 } } },

const paths = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);
paths.push(eventInfo.path.resolved);
});
state.subscribe('one.two.*.four', (val, eventInfo) => {
state.subscribe("one.two.*.four", (val, eventInfo) => {
values.push(val);

@@ -703,10 +693,10 @@ paths.push(eventInfo.path.resolved);

expect(values.length).toEqual(2);
state.update('one.two', { three: { four: 44 } }, { only: ['*.four'] });
state.update("one.two", { three: { four: 44 } }, { only: ["*.four"] });
expect(paths.length).toEqual(3);
expect(values[2]).toEqual(44);
expect(paths[2]).toEqual('one.two.three.four');
expect(state.get('one.two.three.four')).toEqual(44);
expect(paths[2]).toEqual("one.two.three.four");
expect(state.get("one.two.three.four")).toEqual(44);
});
it('should notify only specified strict listeners (nested & wildcard & bulk)', () => {
it("should notify only specified strict listeners (nested & wildcard & bulk)", () => {
const base = {

@@ -716,3 +706,3 @@ one: { two: { three: { four: 4 } } },

for (let i = 1; i < 10; i++) {
base.one.two['three' + i] = { four: 4 };
base.one.two["three" + i] = { four: 4 };
}

@@ -722,3 +712,3 @@ const state = new State(base);

const paths = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);

@@ -728,6 +718,6 @@ paths.push(eventInfo.path.resolved);

state.subscribe(
'one.two.*.four',
"one.two.*.four",
(bulk) => {
values.push('bulk');
paths.push('bulk');
values.push("bulk");
paths.push("bulk");
},

@@ -738,5 +728,5 @@ { bulk: true }

state.update(
'one.two',
"one.two",
(current) => {
const two = state.get('one.two');
const two = state.get("one.two");
for (const three in two) {

@@ -747,12 +737,12 @@ two[three] = { four: 44 };

},
{ only: ['*.four'] }
{ only: ["*.four"] }
);
expect(paths.length).toEqual(3);
expect(values[2]).toEqual('bulk');
expect(paths[2]).toEqual('bulk');
expect(state.get('one.two.three.four')).toEqual(44);
expect(state.get('one.two.three8.four')).toEqual(44);
expect(values[2]).toEqual("bulk");
expect(paths[2]).toEqual("bulk");
expect(state.get("one.two.three.four")).toEqual(44);
expect(state.get("one.two.three8.four")).toEqual(44);
});
it('should notify only specified strict listeners (nested & wildcard)', () => {
it("should notify only specified strict listeners (nested & wildcard)", () => {
const state = new State({

@@ -763,7 +753,7 @@ one: { two: { three: { four: 4 } } },

const paths = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);
paths.push(eventInfo.path.resolved);
});
state.subscribe('one.two.three.four', (val, eventInfo) => {
state.subscribe("one.two.three.four", (val, eventInfo) => {
values.push(val);

@@ -773,33 +763,33 @@ paths.push(eventInfo.path.resolved);

expect(values.length).toEqual(2);
state.update('one.two', { three: { four: 44 } }, { only: ['*.four'] });
state.update("one.two", { three: { four: 44 } }, { only: ["*.four"] });
expect(paths.length).toEqual(3);
expect(values[2]).toEqual(44);
expect(paths[2]).toEqual('one.two.three.four');
expect(state.get('one.two.three.four')).toEqual(44);
expect(paths[2]).toEqual("one.two.three.four");
expect(state.get("one.two.three.four")).toEqual(44);
});
it('should destroy listeners', () => {
const state = new State({ test: 'x' });
it("should destroy listeners", () => {
const state = new State({ test: "x" });
const values = [];
const first = state.subscribe('test', (test) => {
const first = state.subscribe("test", (test) => {
values.push(test);
});
const second = state.subscribe('test', (test) => {
values.push(test + '2');
const second = state.subscribe("test", (test) => {
values.push(test + "2");
});
expect(values.length).toEqual(2);
expect(values[0]).toEqual('x');
expect(values[1]).toEqual('x2');
state.update('test', 'x3');
expect(values[0]).toEqual("x");
expect(values[1]).toEqual("x2");
state.update("test", "x3");
expect(values.length).toEqual(4);
expect(values[2]).toEqual('x3');
expect(values[3]).toEqual('x32');
expect(values[2]).toEqual("x3");
expect(values[3]).toEqual("x32");
first();
state.update('test', 'xx');
state.update("test", "xx");
expect(values.length).toEqual(5);
expect(values[4]).toEqual('xx2');
expect(values[4]).toEqual("xx2");
second();
state.update('test', 'xxx');
state.update("test", "xxx");
expect(values.length).toEqual(5);
expect(values[4]).toEqual('xx2');
expect(values[4]).toEqual("xx2");

@@ -809,3 +799,3 @@ expect(state.listeners.size).toEqual(0);

it('should add valid event info path object', () => {
it("should add valid event info path object", () => {
const state = new State({

@@ -816,11 +806,11 @@ one: { two: { three: { four: 4 } } },

const events = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);
events.push(eventInfo);
});
state.subscribe('one.two.*.four', (val, eventInfo) => {
state.subscribe("one.two.*.four", (val, eventInfo) => {
values.push(val);
events.push(eventInfo);
});
state.subscribe('one.two.three.four', (val, eventInfo) => {
state.subscribe("one.two.three.four", (val, eventInfo) => {
values.push(val);

@@ -830,5 +820,5 @@ events.push(eventInfo);

expect(events.length).toEqual(3);
expect(events[0].path.resolved).toEqual('one.two');
expect(events[1].path.resolved).toEqual('one.two.three.four');
expect(events[2].path.resolved).toEqual('one.two.three.four');
expect(events[0].path.resolved).toEqual("one.two");
expect(events[1].path.resolved).toEqual("one.two.three.four");
expect(events[2].path.resolved).toEqual("one.two.three.four");

@@ -839,36 +829,36 @@ expect(events[0].path.update).toEqual(undefined);

expect(events[0].path.listener).toEqual('one.two');
expect(events[1].path.listener).toEqual('one.two.*.four');
expect(events[2].path.listener).toEqual('one.two.three.four');
expect(events[0].path.listener).toEqual("one.two");
expect(events[1].path.listener).toEqual("one.two.*.four");
expect(events[2].path.listener).toEqual("one.two.three.four");
state.update('one.two.three.four', 44);
state.update("one.two.three.four", 44);
expect(events.length).toEqual(6);
expect(events[3].path.resolved).toEqual('one.two.three.four');
expect(events[4].path.resolved).toEqual('one.two.three.four');
expect(events[5].path.resolved).toEqual('one.two.three.four');
expect(events[3].path.resolved).toEqual("one.two.three.four");
expect(events[4].path.resolved).toEqual("one.two.three.four");
expect(events[5].path.resolved).toEqual("one.two.three.four");
expect(events[3].path.update).toEqual('one.two.three.four');
expect(events[4].path.update).toEqual('one.two.three.four');
expect(events[5].path.update).toEqual('one.two.three.four');
expect(events[3].path.update).toEqual("one.two.three.four");
expect(events[4].path.update).toEqual("one.two.three.four");
expect(events[5].path.update).toEqual("one.two.three.four");
expect(events[3].path.listener).toEqual('one.two');
expect(events[4].path.listener).toEqual('one.two.*.four');
expect(events[5].path.listener).toEqual('one.two.three.four');
expect(events[3].path.listener).toEqual("one.two");
expect(events[4].path.listener).toEqual("one.two.*.four");
expect(events[5].path.listener).toEqual("one.two.three.four");
state.update('one.two.*.four', 444);
state.update("one.two.*.four", 444);
expect(events.length).toEqual(9);
expect(events[6].path.resolved).toEqual('one.two.three.four');
expect(events[7].path.resolved).toEqual('one.two.three.four');
expect(events[8].path.resolved).toEqual('one.two.three.four');
expect(events[6].path.resolved).toEqual("one.two.three.four");
expect(events[7].path.resolved).toEqual("one.two.three.four");
expect(events[8].path.resolved).toEqual("one.two.three.four");
expect(events[6].path.update).toEqual('one.two.*.four');
expect(events[7].path.update).toEqual('one.two.*.four');
expect(events[8].path.update).toEqual('one.two.*.four');
expect(events[6].path.update).toEqual("one.two.*.four");
expect(events[7].path.update).toEqual("one.two.*.four");
expect(events[8].path.update).toEqual("one.two.*.four");
expect(events[6].path.listener).toEqual('one.two');
expect(events[7].path.listener).toEqual('one.two.*.four');
expect(events[8].path.listener).toEqual('one.two.three.four');
expect(events[6].path.listener).toEqual("one.two");
expect(events[7].path.listener).toEqual("one.two.*.four");
expect(events[8].path.listener).toEqual("one.two.three.four");
});
it('should add valid event info type', () => {
it("should add valid event info type", () => {
const state = new State({

@@ -879,11 +869,11 @@ one: { two: { three: { four: 4 } } },

const events = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);
events.push(eventInfo);
});
state.subscribe('one.two.*.four', (val, eventInfo) => {
state.subscribe("one.two.*.four", (val, eventInfo) => {
values.push(val);
events.push(eventInfo);
});
state.subscribe('one.two.three.four', (val, eventInfo) => {
state.subscribe("one.two.three.four", (val, eventInfo) => {
values.push(val);

@@ -893,14 +883,14 @@ events.push(eventInfo);

expect(events.length).toEqual(3);
expect(events[0].type).toEqual('subscribe');
expect(events[1].type).toEqual('subscribe');
expect(events[2].type).toEqual('subscribe');
expect(events[0].type).toEqual("subscribe");
expect(events[1].type).toEqual("subscribe");
expect(events[2].type).toEqual("subscribe");
state.update('one.*.three.four', 44);
state.update("one.*.three.four", 44);
expect(events.length).toEqual(6);
expect(events[3].type).toEqual('update');
expect(events[4].type).toEqual('update');
expect(events[5].type).toEqual('update');
expect(events[3].type).toEqual("update");
expect(events[4].type).toEqual("update");
expect(events[5].type).toEqual("update");
});
it('should add two listeners with the same path but with different recursive option', () => {
it("should add two listeners with the same path but with different recursive option", () => {
const state = new State({

@@ -911,3 +901,3 @@ one: { two: { three: { four: 4 } } },

const events = [];
state.subscribe('one.two', (val, eventInfo) => {
state.subscribe("one.two", (val, eventInfo) => {
values.push(val);

@@ -919,3 +909,3 @@ events.push({

});
state.subscribe('one.two;', (val, eventInfo) => {
state.subscribe("one.two;", (val, eventInfo) => {
values.push(val);

@@ -928,23 +918,21 @@ events.push({

expect(values.length).toEqual(2);
expect(events[0].path.listener).toEqual('one.two');
expect(events[1].path.listener).toEqual('one.two;');
expect(events[0].path.listener).toEqual("one.two");
expect(events[1].path.listener).toEqual("one.two;");
expect(events[0].listenersCollection.isRecursive).toEqual(true);
expect(events[1].listenersCollection.isRecursive).toEqual(false);
expect(events[0].listenersCollection).not.toEqual(
events[1].listenersCollection
);
expect(state.listeners.get('one.two').count).toEqual(1);
expect(state.listeners.get('one.two;').count).toEqual(1);
expect(events[0].listenersCollection).not.toEqual(events[1].listenersCollection);
expect(state.listeners.get("one.two").count).toEqual(1);
expect(state.listeners.get("one.two;").count).toEqual(1);
});
it('should change data without update', () => {
it("should change data without update", () => {
const state = new State({ x: { y: { z: 2 } }, xx: 22 });
expect(state.get('x.y.z')).toEqual(2);
const y = state.get('x.y');
expect(state.get("x.y.z")).toEqual(2);
const y = state.get("x.y");
y.z = 22;
expect(state.get('x.y.z')).toEqual(22);
expect(state.get("x.y.z")).toEqual(22);
expect(state.data.x.y.z).toEqual(22);
});
it('should ignore ignored changes', () => {
it("should ignore ignored changes", () => {
const state = new State({ one: { two: { three: { four: { five: 0 } } } } });

@@ -954,7 +942,7 @@ const values = [];

state.subscribe(
'one.two.three',
"one.two.three",
(val) => {
values.push(val);
},
{ ignore: ['one.two.three.four'] }
{ ignore: ["one.two.three.four"] }
);

@@ -965,15 +953,15 @@

state.update('one.two.three.four.five', 1);
state.update("one.two.three.four.five", 1);
expect(values.length).toEqual(1);
state.update('one.two.three.*.five', 1);
state.update("one.two.three.*.five", 1);
expect(values.length).toEqual(1);
state.update('one.two.three.four', 1);
state.update("one.two.three.four", 1);
expect(values.length).toEqual(1);
state.update('one.two.*.four', 2);
state.update("one.two.*.four", 2);
expect(values.length).toEqual(1);
state.update('one.two.three', 1);
state.update("one.two.three", 1);
expect(values.length).toEqual(2);

@@ -983,3 +971,3 @@ expect(values[1]).toEqual(1);

it('should ignore wildcard ignored changes', () => {
it("should ignore wildcard ignored changes", () => {
const state = new State({ one: { two: { three: { four: { five: 0 } } } } });

@@ -989,7 +977,7 @@ const values = [];

state.subscribe(
'one.two.three',
"one.two.three",
(val) => {
values.push(val);
},
{ ignore: ['one.two.*.four'] }
{ ignore: ["one.two.*.four"] }
);

@@ -1000,15 +988,15 @@

state.update('one.two.three.four.five', 1);
state.update("one.two.three.four.five", 1);
expect(values.length).toEqual(1);
state.update('one.two.three.*.five', 1);
state.update("one.two.three.*.five", 1);
expect(values.length).toEqual(1);
state.update('one.two.three.four', 1);
state.update("one.two.three.four", 1);
expect(values.length).toEqual(1);
state.update('one.two.*.four', 2);
state.update("one.two.*.four", 2);
expect(values.length).toEqual(1);
state.update('one.two.three', 1);
state.update("one.two.three", 1);
expect(values.length).toEqual(2);

@@ -1018,15 +1006,13 @@ expect(values[1]).toEqual(1);

it('should work with experimental matcher', async () => {
it("should work with experimental matcher", async () => {
const state = new State({ one: { two: { three: { four: { five: 0 } } } } });
await state.loadWasmMatcher(
fs.readFileSync(path.resolve('./wildcard_matcher_bg.wasm'))
);
await state.loadWasmMatcher(fs.readFileSync(path.resolve("./wildcard_matcher_bg.wasm")));
const values = [];
state.subscribe(
'one.two.three',
"one.two.three",
(val) => {
values.push(val);
},
{ ignore: ['one.two.*.four'] }
{ ignore: ["one.two.*.four"] }
);

@@ -1037,15 +1023,15 @@

state.update('one.two.three.four.five', 1);
state.update("one.two.three.four.five", 1);
expect(values.length).toEqual(1);
state.update('one.two.three.*.five', 1);
state.update("one.two.three.*.five", 1);
expect(values.length).toEqual(1);
state.update('one.two.three.four', 1);
state.update("one.two.three.four", 1);
expect(values.length).toEqual(1);
state.update('one.two.*.four', 2);
state.update("one.two.*.four", 2);
expect(values.length).toEqual(1);
state.update('one.two.three', 1);
state.update("one.two.three", 1);
expect(values.length).toEqual(2);

@@ -1055,10 +1041,10 @@ expect(values[1]).toEqual(1);

it('should force update and notify listeners even if value is the same', () => {
it("should force update and notify listeners even if value is the same", () => {
const state = new State({ one: { two: { three: { four: { five: 0 } } } } });
const values1 = [],
values2 = [];
state.subscribe('one.two.three.four.five', (val) => {
state.subscribe("one.two.three.four.five", (val) => {
values1.push(val);
});
state.subscribe('one.*.three.four.five', (val) => {
state.subscribe("one.*.three.four.five", (val) => {
values2.push(val);

@@ -1070,3 +1056,3 @@ });

state.update('one.*.three.four.five', 6);
state.update("one.*.three.four.five", 6);
expect(values1.length).toEqual(2);

@@ -1077,3 +1063,3 @@ expect(values2.length).toEqual(2);

state.update('one.*.three.four.five', 6);
state.update("one.*.three.four.five", 6);
expect(values1.length).toEqual(2);

@@ -1084,3 +1070,3 @@ expect(values2.length).toEqual(2);

state.update('one.*.three.four.five', 6, { force: true });
state.update("one.*.three.four.five", 6, { force: true });
expect(values1.length).toEqual(3);

@@ -1091,3 +1077,3 @@ expect(values2.length).toEqual(3);

state.update('one.two.three.four.five', 6);
state.update("one.two.three.four.five", 6);
expect(values1.length).toEqual(3);

@@ -1098,3 +1084,3 @@ expect(values2.length).toEqual(3);

state.update('one.two.three.four.five', 6, { force: true });
state.update("one.two.three.four.five", 6, { force: true });
expect(values1.length).toEqual(4);

@@ -1106,76 +1092,76 @@ expect(values2.length).toEqual(4);

it('should mute some updates', () => {
const state = new State({ x: { z: 'z', i: { o: 'o' } }, y: 'y' });
it("should mute some updates", () => {
const state = new State({ x: { z: "z", i: { o: "o" } }, y: "y" });
const values = [];
state.subscribe('x.*.o', (val) => {
state.subscribe("x.*.o", (val) => {
values.push(val);
});
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
state.mute('x.i.o');
state.update('x.i.o', 'oo');
expect(values[0]).toEqual("o");
state.mute("x.i.o");
state.update("x.i.o", "oo");
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
expect(values[0]).toEqual("o");
});
it('should mute some wildcard updates #1', () => {
const state = new State({ x: { z: 'z', i: { o: 'o' } }, y: 'y' });
it("should mute some wildcard updates #1", () => {
const state = new State({ x: { z: "z", i: { o: "o" } }, y: "y" });
const values = [];
state.subscribe('x.i.o', (val) => {
state.subscribe("x.i.o", (val) => {
values.push(val);
});
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
state.mute('x.*.o');
state.update('x.i.o', 'oo');
expect(values[0]).toEqual("o");
state.mute("x.*.o");
state.update("x.i.o", "oo");
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
expect(values[0]).toEqual("o");
});
it('should mute some wildcard updates #2', () => {
const state = new State({ x: { z: 'z', i: { o: 'o' } }, y: 'y' });
it("should mute some wildcard updates #2", () => {
const state = new State({ x: { z: "z", i: { o: "o" } }, y: "y" });
const values = [];
state.subscribe('x.*.o', (val) => {
state.subscribe("x.*.o", (val) => {
values.push(val);
});
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
state.mute('x.*.o');
state.update('x.i.o', 'oo');
expect(values[0]).toEqual("o");
state.mute("x.*.o");
state.update("x.i.o", "oo");
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
expect(values[0]).toEqual("o");
});
it('should mute some wildcard updates #3', () => {
const state = new State({ x: { z: 'z', i: { o: 'o' } }, y: 'y' });
it("should mute some wildcard updates #3", () => {
const state = new State({ x: { z: "z", i: { o: "o" } }, y: "y" });
const values = [];
state.subscribe('x.*.o', (val) => {
state.subscribe("x.*.o", (val) => {
values.push(val);
});
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
state.mute('x.*.o');
state.update('x.*.o', 'oo');
expect(values[0]).toEqual("o");
state.mute("x.*.o");
state.update("x.*.o", "oo");
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
expect(values[0]).toEqual("o");
});
it('should mute nested properties', () => {
const state = new State({ x: { z: 'z', i: { o: 'o' } }, y: 'y' });
it("should mute nested properties", () => {
const state = new State({ x: { z: "z", i: { o: "o" } }, y: "y" });
const values = [];
state.subscribe('x.i.o', (val) => {
state.subscribe("x.i.o", (val) => {
values.push(val);
});
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
state.mute('x');
state.update('x.*.o', 'oo');
expect(values[0]).toEqual("o");
state.mute("x");
state.update("x.*.o", "oo");
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
expect(values[0]).toEqual("o");
});
it('should not mute nested properties', () => {
const state = new State({ x: { z: 'z', i: { o: 'o' } }, y: 'y' });
it("should not mute nested properties", () => {
const state = new State({ x: { z: "z", i: { o: "o" } }, y: "y" });
const values = [];
state.subscribe('x.i.o', (val) => {
state.subscribe("x.i.o", (val) => {
values.push(val);

@@ -1185,22 +1171,22 @@ });

let lastX = 0;
state.subscribe('x', (val) => {
state.subscribe("x", (val) => {
values2.push(lastX++);
});
expect(values.length).toEqual(1);
expect(values[0]).toEqual('o');
expect(values[0]).toEqual("o");
expect(values2.length).toEqual(1);
expect(values2[0]).toEqual(0);
state.mute('x;');
state.update('x.*.o', 'oo');
state.mute("x;");
state.update("x.*.o", "oo");
expect(values.length).toEqual(2);
expect(values[1]).toEqual('oo');
expect(values[1]).toEqual("oo");
expect(values2.length).toEqual(1);
expect(values2[0]).toEqual(0);
state.unmute('x;');
state.update('x.*.o', 'ooo');
state.unmute("x;");
state.update("x.*.o", "ooo");
expect(values.length).toEqual(3);
expect(values[2]).toEqual('ooo');
expect(values[2]).toEqual("ooo");
expect(values2.length).toEqual(2);

@@ -1222,49 +1208,49 @@ expect(values2[1]).toEqual(1);

it('should update nested listeners', () => {
const state = new State({ x: { z: 'z', i: { o: 'o' } }, y: 'y' });
it("should update nested listeners", () => {
const state = new State({ x: { z: "z", i: { o: "o" } }, y: "y" });
const values = [];
function listener1() {
values.push('1');
values.push("1");
}
function listener2() {
values.push('2');
values.push("2");
}
function listener3() {
values.push('3');
values.push("3");
}
function listener4() {
values.push('4');
values.push("4");
}
state.subscribe('x.i.o', listener1);
state.subscribe('x.i.o', listener2);
state.subscribe('x.y', listener3);
state.subscribe('x.i', listener4);
expect(values).toEqual(['1', '2', '3', '4']);
state.subscribe("x.i.o", listener1);
state.subscribe("x.i.o", listener2);
state.subscribe("x.y", listener3);
state.subscribe("x.i", listener4);
expect(values).toEqual(["1", "2", "3", "4"]);
values.length = 0;
state.update('x', { z: 'zz', i: { o: 'oooo' } });
expect(values).toEqual(['1', '2', '4']);
state.update("x", { z: "zz", i: { o: "oooo" } });
expect(values).toEqual(["1", "2", "4"]);
});
it('should mute specified listeners', () => {
const state = new State({ x: { z: 'z', i: { o: 'o' } }, y: 'y' });
it("should mute specified listeners", () => {
const state = new State({ x: { z: "z", i: { o: "o" } }, y: "y" });
const values = [];
function listener1() {
values.push('1');
values.push("1");
}
function listener2() {
values.push('2');
values.push("2");
}
function listener3() {
values.push('3');
values.push("3");
}
function listener4() {
values.push('4');
values.push("4");
}
state.subscribe('x.i.o', listener1);
state.subscribe('x.i.o', listener2);
state.subscribe('x.y', listener3);
state.subscribe('x.i', listener4);
state.subscribe("x.i.o", listener1);
state.subscribe("x.i.o", listener2);
state.subscribe("x.y", listener3);
state.subscribe("x.i", listener4);
expect(values.length).toEqual(4);
expect(values).toEqual(['1', '2', '3', '4']);
expect(values).toEqual(["1", "2", "3", "4"]);

@@ -1279,5 +1265,5 @@ state.mute(listener2);

values.length = 0;
state.update('x.i.o', 'oo');
state.update("x.i.o", "oo");
expect(values.length).toEqual(2);
expect(values).toEqual(['1', '4']);
expect(values).toEqual(["1", "4"]);

@@ -1290,5 +1276,5 @@ expect(state.isMuted(listener1)).toEqual(false);

values.length = 0;
state.update('x.i', { o: 'ooo' });
state.update("x.i", { o: "ooo" });
expect(values.length).toEqual(2);
expect(values).toEqual(['1', '4']);
expect(values).toEqual(["1", "4"]);

@@ -1301,4 +1287,4 @@ expect(state.isMuted(listener1)).toEqual(false);

values.length = 0;
state.update('x', { z: 'zz', i: { o: 'oooo' } });
expect(values).toEqual(['1', '4']);
state.update("x", { z: "zz", i: { o: "oooo" } });
expect(values).toEqual(["1", "4"]);

@@ -1319,4 +1305,4 @@ expect(state.isMuted(listener1)).toEqual(false);

values.length = 0;
state.update('x', { z: 'zzz', i: { o: 'ooooo' } });
expect(values).toEqual(['2', '4']);
state.update("x", { z: "zzz", i: { o: "ooooo" } });
expect(values).toEqual(["2", "4"]);

@@ -1336,4 +1322,4 @@ expect(state.isMuted(listener1)).toEqual(true);

values.length = 0;
state.update('x', { z: 'zz', i: { o: 'oooooo' } });
expect(values).toEqual(['1', '2', '4']);
state.update("x", { z: "zz", i: { o: "oooooo" } });
expect(values).toEqual(["1", "2", "4"]);

@@ -1346,6 +1332,6 @@ expect(state.isMuted(listener1)).toEqual(false);

it('should add two wildcard listeners - one without and one with parameter', () => {
const state = new State({ nested: { value: { equals: 'x' } } });
it("should add two wildcard listeners - one without and one with parameter", () => {
const state = new State({ nested: { value: { equals: "x" } } });
const values = [];
state.subscribe('nested.*.equals', (val, info) => {
state.subscribe("nested.*.equals", (val, info) => {
values.push(val);

@@ -1355,13 +1341,13 @@ expect(info.params).toEqual(undefined);

expect(values.length).toEqual(1);
state.subscribe('nested.:val.equals', (val, info) => {
state.subscribe("nested.:val.equals", (val, info) => {
values.push(val);
expect(info.params).toEqual({ val: 'value' });
expect(info.params).toEqual({ val: "value" });
});
expect(values.length).toEqual(2);
state.update('nested.value.equals', 'y');
state.update("nested.value.equals", "y");
expect(values.length).toEqual(4);
});
it('should run listeners with proper order', () => {
const state = new State({ nested: { value: { equals: { test: 'x' } } } });
it("should run listeners with proper order", () => {
const state = new State({ nested: { value: { equals: { test: "x" } } } });
let values = [];

@@ -1381,14 +1367,14 @@ function first() {

state.subscribe('nested;', first);
state.subscribe('nested.value.equals', second);
state.subscribe('nested.value.equals', third);
state.subscribe('nested', fourth);
state.subscribe("nested;", first);
state.subscribe("nested.value.equals", second);
state.subscribe("nested.value.equals", third);
state.subscribe("nested", fourth);
expect(values).toEqual([1, 2, 3, 4]);
values = [];
state.update('nested', () => {
state.update("nested", () => {
return {
value: {
equals: {
test: 'x',
test: "x",
},

@@ -1402,5 +1388,5 @@ },

it('should run listeners with proper order #2', () => {
it("should run listeners with proper order #2", () => {
const state = new State({
nested: { value: { equals: { test: { x: 'x' } } } },
nested: { value: { equals: { test: { x: "x" } } } },
});

@@ -1415,3 +1401,3 @@ let values = [];

state.subscribe('nested.value.equals.*;', first);
state.subscribe("nested.value.equals.*;", first);
// state.subscribeAll(["nested.value.equals.*.x"], second, {

@@ -1427,4 +1413,4 @@ // bulk: true,

it('should run listeners with proper order (bulk)', () => {
const state = new State({ nested: { value: { equals: { test: 'x' } } } });
it("should run listeners with proper order (bulk)", () => {
const state = new State({ nested: { value: { equals: { test: "x" } } } });
let values = [];

@@ -1444,8 +1430,8 @@ function first() {

state.subscribeAll(['nested.value;'], first, { bulk: true });
state.subscribe('nested.value.equals', second);
state.subscribe('nested.value.equals', third);
state.subscribe('nested.value', fourth, {
state.subscribeAll(["nested.value;"], first, { bulk: true });
state.subscribe("nested.value.equals", second);
state.subscribe("nested.value.equals", third);
state.subscribe("nested.value", fourth, {
bulk: true,
ignore: ['nested.value.*.test'],
ignore: ["nested.value.*.test"],
});

@@ -1455,6 +1441,6 @@ expect(values).toEqual([1, 2, 3, 4]);

values = [];
state.update('nested.value', () => {
state.update("nested.value", () => {
return {
equals: {
test: 'x',
test: "x",
},

@@ -1466,5 +1452,5 @@ };

values = [];
state.update('nested.value.equals', () => {
state.update("nested.value.equals", () => {
return {
test: 'x',
test: "x",
};

@@ -1475,7 +1461,7 @@ });

values = [];
state.update('nested', () => {
state.update("nested", () => {
return {
value: {
equals: {
test: 'x',
test: "x",
},

@@ -1488,5 +1474,5 @@ },

it('should not run nested listener even if it is a wildcard property', () => {
it("should not run nested listener even if it is a wildcard property", () => {
const state = new State({
nested: { value: { equals: { test: { x: 'x' } } } },
nested: { value: { equals: { test: { x: "x" } } } },
});

@@ -1504,13 +1490,13 @@ let values = [];

state.subscribe('nested.value.equals.*;', first);
state.subscribeAll(['nested.value.equals.*;'], second, {
state.subscribe("nested.value.equals.*;", first);
state.subscribeAll(["nested.value.equals.*;"], second, {
bulk: true,
});
state.subscribe('nested.value.equals.test;', third);
state.subscribe("nested.value.equals.test;", third);
expect(values).toEqual([1, 2, 3]);
state.update('nested.value.equals.test.x', 'z');
state.update("nested.value.equals.test.x", "z");
expect(values).toEqual([1, 2, 3]);
});
it('should run listeners in proper order #3', () => {
it("should run listeners in proper order #3", () => {
const state = new State({

@@ -1528,3 +1514,3 @@ config: {

items: {
1: { rowId: '1' },
1: { rowId: "1" },
},

@@ -1537,39 +1523,24 @@ },

function full(val, info) {
values.push('full');
values.push("full");
paths.push(info.path.listener);
}
function partialFull(val, info) {
values.push('partialFull');
values.push("partialFull");
paths.push(info.path.listener);
}
function partial(val, info) {
values.push('partial');
values.push("partial");
paths.push(info.path.listener);
}
state.subscribeAll(['config.chart.items;', 'config.list.rows;'], full);
state.subscribeAll(
['config.list.rows.*;', 'config.list.rows.*.parentId'],
partialFull,
{
bulk: true,
}
);
state.subscribeAll(
['config.chart.items.*.rowId', 'config.list.rows.*.expanded'],
partial,
{
bulk: true,
}
);
expect(values).toEqual([
'full',
'full',
'partialFull',
'partialFull',
'partial',
'partial',
]);
state.subscribeAll(["config.chart.items;", "config.list.rows;"], full);
state.subscribeAll(["config.list.rows.*;", "config.list.rows.*.parentId"], partialFull, {
bulk: true,
});
state.subscribeAll(["config.chart.items.*.rowId", "config.list.rows.*.expanded"], partial, {
bulk: true,
});
expect(values).toEqual(["full", "full", "partialFull", "partialFull", "partial", "partial"]);
values.length = 0;
paths.length = 0;
state.update('config.list.rows', {
state.update("config.list.rows", {
2: {

@@ -1580,15 +1551,11 @@ parentId: null,

});
expect(values).toEqual(['full', 'partialFull', 'partialFull', 'partial']);
expect(values).toEqual(["full", "partialFull", "partialFull", "partial"]);
//console.log(paths);
});
it('it should properly clean not recursive path', () => {
it("it should properly clean not recursive path", () => {
const state = new State({});
expect(state.cleanNotRecursivePath('config.list.rows;')).toEqual(
'config.list.rows'
);
expect(state.cutPath('config.list.rows', 'config.list.rows')).toEqual(
'config.list.rows'
);
expect(state.cleanNotRecursivePath("config.list.rows;")).toEqual("config.list.rows");
expect(state.cutPath("config.list.rows", "config.list.rows")).toEqual("config.list.rows");
});
});

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc