@plcmp/pl-data-observer
Advanced tools
+1
-1
| { | ||
| "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", |
+43
-42
| 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 @@ } |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8186
1.14%168
0.6%0
-100%