@plcmp/pl-data-observer
Advanced tools
+1
-1
| { | ||
| "name": "@plcmp/pl-data-observer", | ||
| "version": "0.1.8", | ||
| "version": "0.1.9", | ||
| "description": "Data mutation observer component", | ||
@@ -5,0 +5,0 @@ "main": "pl-data-observer.js", |
+15
-19
@@ -1,6 +0,6 @@ | ||
| import { PlElement, css } from "polylib"; | ||
| import { normalizePath } from "polylib/common.js"; | ||
| import { PlElement, css } from 'polylib'; | ||
| import { normalizePath } from 'polylib/common.js'; | ||
| class PlDataObserver extends PlElement { | ||
| static properties = { | ||
| static properties = { | ||
| data: { | ||
@@ -17,3 +17,3 @@ type: Array, | ||
| static css = css` | ||
| static css = css` | ||
| :host{ | ||
@@ -25,4 +25,4 @@ display: none; | ||
| setTouch(path, chain, upd) { | ||
| let c = chain.at(-2); | ||
| let a = chain.at(-1); | ||
| const c = chain.at(-2); | ||
| const a = chain.at(-1); | ||
| if (!c) return; | ||
@@ -46,4 +46,4 @@ if (Array.isArray(c)) { | ||
| } | ||
| upd = false; | ||
| } | ||
| upd = false; | ||
| this.setTouch(path.slice(0, -1), chain.slice(0, -1), upd); | ||
@@ -54,5 +54,5 @@ } | ||
| if (!this.data) return; | ||
| let path = normalizePath(mutation.path); | ||
| const path = normalizePath(mutation.path); | ||
| let c = this; | ||
| let chain = path.map(p => c = c[p]); | ||
| const chain = path.map(p => c = c[p]); | ||
| let current = chain.at(-1); | ||
@@ -96,6 +96,3 @@ | ||
| } | ||
| } | ||
| else if (chain.at(-2) instanceof Object && mutation.action === 'upd') { | ||
| } else if (chain.at(-2) instanceof Object && mutation.action === 'upd') { | ||
| current = chain.at(-2); | ||
@@ -121,5 +118,5 @@ if (current._old) { | ||
| if (obj._mutations.upd.length | ||
| || obj._mutations.del.length | ||
| || obj._mutations.add.length | ||
| || obj._mutations.touch.length) { | ||
| || obj._mutations.del.length | ||
| || obj._mutations.add.length | ||
| || obj._mutations.touch.length) { | ||
| return true; | ||
@@ -130,5 +127,4 @@ } | ||
| for (let i = 0, c = obj.length; i < c; i++) { | ||
| let o = obj[i]; | ||
| if (o instanceof Object && this._checkMutation(o)) | ||
| return true; | ||
| const o = obj[i]; | ||
| if (o instanceof Object && this._checkMutation(o)) return true; | ||
| } | ||
@@ -135,0 +131,0 @@ } else if (obj instanceof Object) { |
8024
-0.4%162
-1.22%