Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@plcmp/pl-data-observer

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plcmp/pl-data-observer - npm Package Compare versions

Comparing version
0.1.5
to
0.1.6
+1
-1
package.json
{
"name": "@plcmp/pl-data-observer",
"version": "0.1.5",
"version": "0.1.6",
"description": "Data mutation observer component",

@@ -5,0 +5,0 @@ "main": "pl-data-observer.js",

import { PlElement, css } from "polylib";
import {normalizePath} from "polylib/common.js";
import { normalizePath } from "polylib/common.js";
class PlDataObserver extends PlElement {
static get properties() {
return {
data: {
type: Array,
value: () => [],
observer: '_dataChanged'
},
isChanged: {
type: Boolean,
value: false
}
};
}
static properties = {
data: {
type: Array,
value: () => [],
observer: '_dataChanged'
},
isChanged: {
type: Boolean,
value: false
}
};
static get css() {
return css`
:host{
display: none;
}
`;
}
static css = css`
:host{
display: none;
}
`;

@@ -32,5 +28,5 @@ setTouch(path, chain, upd) {

if (Array.isArray(c)) {
c._mutations = c._mutations || {upd: [], del: [], add: [], touch: []};
c._mutations = c._mutations || { upd: [], del: [], add: [], touch: [] };
if (this._checkMutation(a, upd)) {
if ( upd && c._mutations.add.indexOf(a) < 0 && c._mutations.upd.indexOf(a) < 0 ) {
if (upd && c._mutations.add.indexOf(a) < 0 && c._mutations.upd.indexOf(a) < 0) {
c._mutations.upd.push(a);

@@ -58,3 +54,3 @@ } else if (!upd && c._mutations.add.indexOf(a) < 0 && c._mutations.upd.indexOf(a) < 0 && c._mutations.touch.indexOf(a) < 0) {

let c = this;
let chain = path.map( p => c = c[p] );
let chain = path.map(p => c = c[p]);
let current = chain.at(-1);

@@ -112,5 +108,7 @@

reset(obj) {
this.isChanged = false;
this._isChangedArray = false;
this._clearMutation(obj);
setTimeout(() => {
this.isChanged = false;
this._isChangedArray = false;
this._clearMutation(obj);
}, 0);
}

@@ -142,3 +140,3 @@

} else {
if ( obj._old && o !== obj._old[prop]) return true;
if (obj._old && o !== obj._old[prop]) return true;
}

@@ -170,16 +168,19 @@ }

snapshot(obj) {
this.isChanged = false;
obj = obj || this.data;
if (Array.isArray(obj)) {
obj.forEach((i) => {
if (i instanceof Object) this.snapshot(i);
});
} else {
obj._old = obj._old || {};
Object.keys(obj).forEach((k) => {
if (k === '_old') return;
if (obj[k] instanceof Object && !(obj[k] instanceof Date)) this.snapshot(obj[k]);
else obj._old[k] = obj[k];
});
}
// wait for nested components initialize
setTimeout(() => {
this.isChanged = false;
obj = obj || this.data;
if (Array.isArray(obj)) {
obj.forEach((i) => {
if (i instanceof Object) this.snapshot(i);
});
} else {
obj._old = obj._old || {};
Object.keys(obj).forEach((k) => {
if (k === '_old') return;
if (obj[k] instanceof Object && !(obj[k] instanceof Date)) this.snapshot(obj[k]);
else obj._old[k] = obj[k];
});
}
}, 0);
}

@@ -186,0 +187,0 @@ }