Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-tier

Package Overview
Dependencies
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-tier - npm Package Compare versions

Comparing version 0.6.23 to 0.6.24

3

dist/module/data-tier.js

@@ -52,4 +52,3 @@ import Observable from './object-observer.js';

(change.type === 'insert' || change.type === 'delete') &&
!isNaN(arrPath[arrPath.length - 1]) &&
change.object.length - 1 > arrPath[arrPath.length - 1]) {
!isNaN(arrPath[arrPath.length - 1])) {
changedPath = arrPath.slice(0, -1).join('.');

@@ -56,0 +55,0 @@ arrayFullUpdate = true;

@@ -1,1 +0,1 @@

import Observable from"./object-observer.js";export const ties=new Ties;const PRIVATE_MODEL_SYMBOL=Symbol("private-tie-model-key"),views={},viewsParams=new WeakMap,PARAM_SPLITTER=/\s*=>\s*/,MULTI_PARAMS_SPLITTER=/\s*[,;]\s*/;class Tie{constructor(e){this[PRIVATE_MODEL_SYMBOL]=null,Object.defineProperty(this,"name",{value:e}),Object.seal(this)}get model(){return this[PRIVATE_MODEL_SYMBOL]}set model(e){let t=this[PRIVATE_MODEL_SYMBOL];if(e!==t){let n=ensureObservable(e);n&&n.observe(this.processDataChanges.bind(this)),this[PRIVATE_MODEL_SYMBOL]=n,this.processDataChanges([{path:[]}]),t&&t.revoke()}}processDataChanges(e){let t,n,r,a,o,i,s,l,d,c,f=this.name,u=this[PRIVATE_MODEL_SYMBOL],h=views[f],m=Object.keys(h);if(m.length)for(t=0,n=e.length;t<n;t++)for(a=(r=e[t]).path,Array.isArray(r.object)&&("insert"===r.type||"delete"===r.type)&&!isNaN(a[a.length-1])&&r.object.length-1>a[a.length-1]?(o=a.slice(0,-1).join("."),c=!0):(o=a&&a.length?a.join("."):"",c=!1),i=m.length;i--;)if(0===(s=m[i]).indexOf(o))for(d=(l=h[s]).length;d--;)update(l[d],u,o,c?null:r)}}function Ties(){const e={},t=/^[a-zA-Z0-9]+$/;function n(e){if(!e||"string"!=typeof e)throw new Error("tie name MUST be a non empty string");if(!t.test(e))throw new Error("tie name MUST contain alphanumeric characters ONLY (use "+t+' to check yourself); "'+e+'" not fits')}this.get=function(t){return n(t),e[t]},this.create=function(t,r){if(n(t),e[t])throw new Error("tie ("+t+") is already present and MAY NOT be re-created");let a=new Tie(t);return e[t]=a,views.hasOwnProperty(t)||(views[t]={}),a.model=r,a},this.remove=function(t){n(t),delete views[t];let r=e[t];r&&(r[PRIVATE_MODEL_SYMBOL]&&r[PRIVATE_MODEL_SYMBOL].revoke(),delete e[t])},Object.freeze(this)}function ensureObservable(e){if(void 0===e||null===e)return e;if("object"!=typeof e)throw new Error(e+" is not of type Observable and not an object");if(Observable.isObservable(e))return e;if(Observable){if("function"==typeof e.observe||"function"==typeof e.unobserve||"function"==typeof e.revoke)throw new Error(e+" is not of type Observable and can not be transformed into Observable (some of its functions already implemented?)");return Observable.from(e)}throw new Error(e+" is not of type Observable and no embedded Observable implementation found")}function getPath(e,t){if(!e)return;let n,r=0,a=t.length;for(;r<a;r++){if(n=t[r],!e||!e.hasOwnProperty(n))return;e=e[n]}return e}function setPath(e,t,n){if(!e)return;let r,a=0,o=t.length;for(;a<o-1;a++)e=e[r=t[a]]&&"object"==typeof e[r]?e[r]:e[r]={};e[t[a]]=n}function changeListener(e){let t,n,r,a,o=e.currentTarget;for(a=(t=viewsParams.get(o)).length;a--;)n=t[a],(r=ties.get(n.tieName))?setPath(r[PRIVATE_MODEL_SYMBOL],n.path,o.value):console.warn('no Tie identified by "'+n.tieName+'" found')}function addChangeListenerIfRelevant(e){"INPUT"!==e.nodeName&&"SELECT"!==e.nodeName&&"TEXTAREA"!==e.nodeName||e.addEventListener("change",changeListener)}function delChangeListener(e){e.removeEventListener("change",changeListener)}function add(e){"IFRAME"===e.nodeName?(initDocumentObserver(e.contentDocument),e.addEventListener("load",function(){initDocumentObserver(this.contentDocument),collect(this.contentDocument)}),collect(e.contentDocument)):Node.ELEMENT_NODE===e.nodeType&&(e.localName.indexOf("-")<0&&!e.hasAttribute("is")?processAddedElement(e):customElements.whenDefined(e.getAttribute("is")||e.localName).then(()=>processAddedElement(e)))}function processAddedElement(e){let t,n,r,a,o,i,s,l=0;for(s=(t=extractTieParams(e)).length;l<s;l++)n=t[l].tieName,r=t[l].rawPath,(o=(a=views[n]||(views[n]={}))[r]||(a[r]=[])).indexOf(e)<0&&(o.push(e),viewsParams.set(e,t),update(e,(i=ties.get(n))?i[PRIVATE_MODEL_SYMBOL]:null),addChangeListenerIfRelevant(e))}function extractTieParams(e){let t,n=[];return e&&e.dataset&&(t=e.dataset.tie)&&(n=parseTiePropertiesParam(t)),n}function parseTiePropertyParam(e){if(!e||"string"!=typeof e)throw new Error('invalid tie value; found: "'+e+'"; expected (example): "orders:0.address.street > textContent"');let t,n,r=e.split(PARAM_SPLITTER);if(2!==r.length||!r[1])throw new Error('invalid tie value; found: "'+e+'"; expected (example): "orders:0.address.street > textContent"');if(!(t=r[0].split(":")).length||t.length>2||!t[0])throw new Error('invalid tie value; found: "'+e+'"; expected (example): "orders:0.address.street > textContent"');return n=t.length>1?t[1]:"",{tieName:t[0],rawPath:n,path:n.split("."),targetProperty:r[1]}}function parseTiePropertiesParam(e){if(!e||"string"!=typeof e)throw new Error('invalid tie value; found: "'+e+'"; expected (example): "orders:0.address.street > textContent, orders:0.address.apt > title"');let t=[],n=e.split(MULTI_PARAMS_SPLITTER),r=0,a=n.length;for(;r<a;r++)try{t.push(parseTiePropertyParam(n[r]))}catch(e){console.error("failed to parse one of a multi param parts",e)}return t}function update(e,t,n,r){let a,o,i,s,l=0;for(s=(a=viewsParams.get(e)).length;l<s;l++)o=a[l],n&&0!==o.rawPath.indexOf(n)||(void 0===(i=r&&n===o.rawPath?r.value:getPath(t,o.path))&&(i=""),"value"===o.targetProperty&&"INPUT"===e.nodeName&&"checkbox"===e.type?e.checked=i:e[o.targetProperty]=i)}function collect(e){if(e&&(e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.ELEMENT_NODE)){let t,n;for(t="IFRAME"===e.nodeName?e.contentDocument.getElementsByTagName("*"):e.getElementsByTagName("*"),add(e),n=t.length;n--;)add(t[n])}}function discard(e){if(e&&e.getElementsByTagName){let t,n,r,a,o,i,s,l=e.getElementsByTagName("*"),d=0,c=l.length;for(;d<=c;d++){for(t=d<c?l[d]:e,n=viewsParams.get(t),i=0,s=n.length;i<s;i++)r=n[i],views[r.tieName]&&(o=(a=views[r.tieName][r.rawPath]).indexOf(t))>=0&&(a.splice(o,1),delChangeListener(t));viewsParams.delete(t)}}}function move(e,t,n,r){let a,o,i,s,l,d,c;if(n){for(o=0,i=(a=viewsParams.get(e)).length;o<i;o++)s=a[o],views[s.tieName]&&(d=views[s.tieName][s.rawPath])&&(c=d.indexOf(e))>=0&&d.splice(c,1);delChangeListener(e)}if(r){for(a=parseTiePropertiesParam(r),viewsParams.set(e,a),o=0,i=a.length;o<i;o++)s=a[o],(d=(l=views[s.tieName]||(views[s.tieName]={}))[s.rawPath]||(l[s.rawPath]=[])).indexOf(e)<0&&(d.push(e),update(e,ties.get(s.tieName)[PRIVATE_MODEL_SYMBOL],s.rawPath));addChangeListenerIfRelevant(e)}}function processDomChanges(e){let t,n,r,a,o,i,s,l,d=0,c=e.length;for(;d<c;d++)if("attributes"===(r=(n=e[d]).type))"data-tie"===(a=n.attributeName)?move(t=n.target,a,n.oldValue,t.getAttribute(a)):"src"===a&&"IFRAME"===(t=n.target).nodeName&&discard(t.contentDocument);else if("childList"===r){for(i=(o=n.addedNodes).length;i--;)"IFRAME"===(t=o[i]).nodeName?(t.contentDocument&&(initDocumentObserver(t.contentDocument),collect(t.contentDocument)),t.addEventListener("load",function(){initDocumentObserver(this.contentDocument),collect(this.contentDocument)})):t.nodeType!==Node.DOCUMENT_NODE&&t.nodeType!==Node.ELEMENT_NODE||collect(t);for(l=(s=n.removedNodes).length;l--;)"IFRAME"===(t=s[l]).nodeName?discard(t.contentDocument):t.nodeType!==Node.DOCUMENT_NODE&&t.nodeType!==Node.ELEMENT_NODE||discard(t)}}function initDocumentObserver(e){new MutationObserver(processDomChanges).observe(e,{childList:!0,attributes:!0,characterData:!1,subtree:!0,attributeOldValue:!0,characterDataOldValue:!1})}initDocumentObserver(document),collect(document);
import Observable from"./object-observer.js";export const ties=new Ties;const PRIVATE_MODEL_SYMBOL=Symbol("private-tie-model-key"),views={},viewsParams=new WeakMap,PARAM_SPLITTER=/\s*=>\s*/,MULTI_PARAMS_SPLITTER=/\s*[,;]\s*/;class Tie{constructor(e){this[PRIVATE_MODEL_SYMBOL]=null,Object.defineProperty(this,"name",{value:e}),Object.seal(this)}get model(){return this[PRIVATE_MODEL_SYMBOL]}set model(e){let t=this[PRIVATE_MODEL_SYMBOL];if(e!==t){let n=ensureObservable(e);n&&n.observe(this.processDataChanges.bind(this)),this[PRIVATE_MODEL_SYMBOL]=n,this.processDataChanges([{path:[]}]),t&&t.revoke()}}processDataChanges(e){let t,n,r,a,o,i,s,l,d,c,f=this.name,u=this[PRIVATE_MODEL_SYMBOL],h=views[f],m=Object.keys(h);if(m.length)for(t=0,n=e.length;t<n;t++)for(a=(r=e[t]).path,!Array.isArray(r.object)||"insert"!==r.type&&"delete"!==r.type||isNaN(a[a.length-1])?(o=a&&a.length?a.join("."):"",c=!1):(o=a.slice(0,-1).join("."),c=!0),i=m.length;i--;)if(0===(s=m[i]).indexOf(o))for(d=(l=h[s]).length;d--;)update(l[d],u,o,c?null:r)}}function Ties(){const e={},t=/^[a-zA-Z0-9]+$/;function n(e){if(!e||"string"!=typeof e)throw new Error("tie name MUST be a non empty string");if(!t.test(e))throw new Error("tie name MUST contain alphanumeric characters ONLY (use "+t+' to check yourself); "'+e+'" not fits')}this.get=function(t){return n(t),e[t]},this.create=function(t,r){if(n(t),e[t])throw new Error("tie ("+t+") is already present and MAY NOT be re-created");let a=new Tie(t);return e[t]=a,views.hasOwnProperty(t)||(views[t]={}),a.model=r,a},this.remove=function(t){n(t),delete views[t];let r=e[t];r&&(r[PRIVATE_MODEL_SYMBOL]&&r[PRIVATE_MODEL_SYMBOL].revoke(),delete e[t])},Object.freeze(this)}function ensureObservable(e){if(void 0===e||null===e)return e;if("object"!=typeof e)throw new Error(e+" is not of type Observable and not an object");if(Observable.isObservable(e))return e;if(Observable){if("function"==typeof e.observe||"function"==typeof e.unobserve||"function"==typeof e.revoke)throw new Error(e+" is not of type Observable and can not be transformed into Observable (some of its functions already implemented?)");return Observable.from(e)}throw new Error(e+" is not of type Observable and no embedded Observable implementation found")}function getPath(e,t){if(!e)return;let n,r=0,a=t.length;for(;r<a;r++){if(n=t[r],!e||!e.hasOwnProperty(n))return;e=e[n]}return e}function setPath(e,t,n){if(!e)return;let r,a=0,o=t.length;for(;a<o-1;a++)e=e[r=t[a]]&&"object"==typeof e[r]?e[r]:e[r]={};e[t[a]]=n}function changeListener(e){let t,n,r,a,o=e.currentTarget;for(a=(t=viewsParams.get(o)).length;a--;)n=t[a],(r=ties.get(n.tieName))?setPath(r[PRIVATE_MODEL_SYMBOL],n.path,o.value):console.warn('no Tie identified by "'+n.tieName+'" found')}function addChangeListenerIfRelevant(e){"INPUT"!==e.nodeName&&"SELECT"!==e.nodeName&&"TEXTAREA"!==e.nodeName||e.addEventListener("change",changeListener)}function delChangeListener(e){e.removeEventListener("change",changeListener)}function add(e){"IFRAME"===e.nodeName?(initDocumentObserver(e.contentDocument),e.addEventListener("load",function(){initDocumentObserver(this.contentDocument),collect(this.contentDocument)}),collect(e.contentDocument)):Node.ELEMENT_NODE===e.nodeType&&(e.localName.indexOf("-")<0&&!e.hasAttribute("is")?processAddedElement(e):customElements.whenDefined(e.getAttribute("is")||e.localName).then(()=>processAddedElement(e)))}function processAddedElement(e){let t,n,r,a,o,i,s,l=0;for(s=(t=extractTieParams(e)).length;l<s;l++)n=t[l].tieName,r=t[l].rawPath,(o=(a=views[n]||(views[n]={}))[r]||(a[r]=[])).indexOf(e)<0&&(o.push(e),viewsParams.set(e,t),update(e,(i=ties.get(n))?i[PRIVATE_MODEL_SYMBOL]:null),addChangeListenerIfRelevant(e))}function extractTieParams(e){let t,n=[];return e&&e.dataset&&(t=e.dataset.tie)&&(n=parseTiePropertiesParam(t)),n}function parseTiePropertyParam(e){if(!e||"string"!=typeof e)throw new Error('invalid tie value; found: "'+e+'"; expected (example): "orders:0.address.street > textContent"');let t,n,r=e.split(PARAM_SPLITTER);if(2!==r.length||!r[1])throw new Error('invalid tie value; found: "'+e+'"; expected (example): "orders:0.address.street > textContent"');if(!(t=r[0].split(":")).length||t.length>2||!t[0])throw new Error('invalid tie value; found: "'+e+'"; expected (example): "orders:0.address.street > textContent"');return n=t.length>1?t[1]:"",{tieName:t[0],rawPath:n,path:n.split("."),targetProperty:r[1]}}function parseTiePropertiesParam(e){if(!e||"string"!=typeof e)throw new Error('invalid tie value; found: "'+e+'"; expected (example): "orders:0.address.street > textContent, orders:0.address.apt > title"');let t=[],n=e.split(MULTI_PARAMS_SPLITTER),r=0,a=n.length;for(;r<a;r++)try{t.push(parseTiePropertyParam(n[r]))}catch(e){console.error("failed to parse one of a multi param parts",e)}return t}function update(e,t,n,r){let a,o,i,s,l=0;for(s=(a=viewsParams.get(e)).length;l<s;l++)o=a[l],n&&0!==o.rawPath.indexOf(n)||(void 0===(i=r&&n===o.rawPath?r.value:getPath(t,o.path))&&(i=""),"value"===o.targetProperty&&"INPUT"===e.nodeName&&"checkbox"===e.type?e.checked=i:e[o.targetProperty]=i)}function collect(e){if(e&&(e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.ELEMENT_NODE)){let t,n;for(t="IFRAME"===e.nodeName?e.contentDocument.getElementsByTagName("*"):e.getElementsByTagName("*"),add(e),n=t.length;n--;)add(t[n])}}function discard(e){if(e&&e.getElementsByTagName){let t,n,r,a,o,i,s,l=e.getElementsByTagName("*"),d=0,c=l.length;for(;d<=c;d++){for(t=d<c?l[d]:e,n=viewsParams.get(t),i=0,s=n.length;i<s;i++)r=n[i],views[r.tieName]&&(o=(a=views[r.tieName][r.rawPath]).indexOf(t))>=0&&(a.splice(o,1),delChangeListener(t));viewsParams.delete(t)}}}function move(e,t,n,r){let a,o,i,s,l,d,c;if(n){for(o=0,i=(a=viewsParams.get(e)).length;o<i;o++)s=a[o],views[s.tieName]&&(d=views[s.tieName][s.rawPath])&&(c=d.indexOf(e))>=0&&d.splice(c,1);delChangeListener(e)}if(r){for(a=parseTiePropertiesParam(r),viewsParams.set(e,a),o=0,i=a.length;o<i;o++)s=a[o],(d=(l=views[s.tieName]||(views[s.tieName]={}))[s.rawPath]||(l[s.rawPath]=[])).indexOf(e)<0&&(d.push(e),update(e,ties.get(s.tieName)[PRIVATE_MODEL_SYMBOL],s.rawPath));addChangeListenerIfRelevant(e)}}function processDomChanges(e){let t,n,r,a,o,i,s,l,d=0,c=e.length;for(;d<c;d++)if("attributes"===(r=(n=e[d]).type))"data-tie"===(a=n.attributeName)?move(t=n.target,a,n.oldValue,t.getAttribute(a)):"src"===a&&"IFRAME"===(t=n.target).nodeName&&discard(t.contentDocument);else if("childList"===r){for(i=(o=n.addedNodes).length;i--;)"IFRAME"===(t=o[i]).nodeName?(t.contentDocument&&(initDocumentObserver(t.contentDocument),collect(t.contentDocument)),t.addEventListener("load",function(){initDocumentObserver(this.contentDocument),collect(this.contentDocument)})):t.nodeType!==Node.DOCUMENT_NODE&&t.nodeType!==Node.ELEMENT_NODE||collect(t);for(l=(s=n.removedNodes).length;l--;)"IFRAME"===(t=s[l]).nodeName?discard(t.contentDocument):t.nodeType!==Node.DOCUMENT_NODE&&t.nodeType!==Node.ELEMENT_NODE||discard(t)}}function initDocumentObserver(e){new MutationObserver(processDomChanges).observe(e,{childList:!0,attributes:!0,characterData:!1,subtree:!0,attributeOldValue:!0,characterDataOldValue:!1})}initDocumentObserver(document),collect(document);
{
"name": "data-tier",
"version": "0.6.23",
"version": "0.6.24",
"description": "Tiny and fast two way (MV-VM) data binding framework for browser environments.",

@@ -5,0 +5,0 @@ "keywords": [

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