data-tier
Advanced tools
Comparing version 0.6.5 to 0.6.6
@@ -38,6 +38,11 @@ (function (scope) { | ||
} | ||
Tie.prototype.viewToDataProcessor = function vanillaViewToDataProcessor(event) { | ||
setPath(event.data, event.path, event.view.value); | ||
}; | ||
function create(name, observable, options) { | ||
validateTieName(name); | ||
validateObservable(observable); | ||
if (observable) { | ||
validateObservable(observable); | ||
} | ||
if (ties[name]) { | ||
@@ -76,2 +81,12 @@ throw new Error('existing tie (' + name + ') MAY NOT be re-created, use the tie\'s own APIs to reconfigure it'); | ||
// TODO: this is similar to getPath in views-service - unify | ||
function setPath(ref, path, value) { | ||
var i; | ||
if (!ref) return; | ||
for (i = 0; i < path.length - 1; i++) { | ||
ref = ref[path[i]] || {}; | ||
} | ||
ref[path[i]] = value; | ||
} | ||
Reflect.defineProperty(scope, 'DataTier', { value: {} }); | ||
@@ -165,2 +180,3 @@ Reflect.defineProperty(scope.DataTier, 'ties', { value: {} }); | ||
// TODO: this is similar to setPath in ties-service - unify | ||
function getPath(ref, path) { | ||
@@ -167,0 +183,0 @@ var i; |
@@ -1,1 +0,1 @@ | ||
!function(a){"use strict";function b(b,c,d){function e(c){a.DataTier.views.processChanges(b,c)}var h;Reflect.defineProperty(this,"name",{value:b}),Reflect.defineProperty(this,"data",{get:function(){return h},set:function(c){c&&(f(c),h&&h.revoke());var d=h;h=c,h&&h.observe(e),a.DataTier.views.processChanges(b,[{type:"update",value:h,oldValue:d,path:[]}])}}),g[b]=this,this.data=c}function c(a,c,d){if(e(a),f(c),g[a])throw new Error("existing tie ("+a+") MAY NOT be re-created, use the tie's own APIs to reconfigure it");return new b(a,c,d)}function d(a){a&&g[a]&&(g[a].observable.revoke(),delete g[a])}function e(a){if(!a||"string"!=typeof a)throw new Error("tie name MUST be a non-empty string");if(/\W/.test(a))throw new Error("tie name MUST consist of alphanumerics or underlines ([a-zA-Z0-9_]) ONLY")}function f(a){if(!a||"object"!=typeof a||"function"!=typeof a.observe||"function"!=typeof a.unobserve||"function"!=typeof a.revoke)throw new Error(a+" is not a valid Observable")}var g={};Reflect.defineProperty(a,"DataTier",{value:{}}),Reflect.defineProperty(a.DataTier,"ties",{value:{}}),Reflect.defineProperty(a.DataTier.ties,"get",{value:function(a){return g[a]}}),Reflect.defineProperty(a.DataTier.ties,"create",{value:c}),Reflect.defineProperty(a.DataTier.ties,"remove",{value:d})}(this),function(a){"use strict";function b(a,b){Reflect.defineProperty(this,"name",{value:a}),Reflect.defineProperty(this,"dataToView",{value:b.dataToView}),"function"==typeof b.inputToData&&Reflect.defineProperty(this,"inputToData",{value:b.inputToData}),"function"==typeof b.parseParam&&Reflect.defineProperty(this,"parseParam",{value:b.parseParam})}function c(c,d){if("string"!=typeof c||!c)throw new Error("name MUST be a non-empty string");if(g[c])throw new Error('rule "'+c+'" already exists; you may want to reconfigure the existing rule');if("object"!=typeof d||!d)throw new Error("configuration MUST be a non-null object");if("function"!=typeof d.dataToView)throw new Error('configuration MUST have a "dataToView" function defined');g[c]=new b(c,d),a.DataTier.views.applyRule(g[c])}function d(a){return g[a]}function e(a){if("string"!=typeof a||!a)throw new Error("rule name MUST be a non-empty string");return delete g[a]}function f(a){var b=[];return a&&a.nodeType===Node.ELEMENT_NODE&&a.dataset&&Reflect.ownKeys(a.dataset).forEach(function(a){g[a]&&b.push(g[a])}),b}var g={};b.prototype.parseParam=function(a){var b,c;return a?(b=a.trim().split("."),c=b.shift(),{tieName:c,dataPath:b}):void console.error("valid rule value MUST be a non-empty string, found: "+a)},Reflect.defineProperty(a.DataTier,"rules",{value:{}}),Reflect.defineProperty(a.DataTier.rules,"get",{value:d}),Reflect.defineProperty(a.DataTier.rules,"add",{value:c}),Reflect.defineProperty(a.DataTier.rules,"remove",{value:e}),Reflect.defineProperty(a.DataTier.rules,"getApplicable",{value:f})}(this),function(a){"use strict";function b(a,b){var c;if(a){for(c=0;c<b.length;c++)if(a=a[b[c]],!a)return;return a}}function c(b){a.DataTier.rules.getApplicable(b.target).forEach(function(c){if("tieValue"===c.name){var d=c.parseParam(b.target.dataset[c.name]),e=a.DataTier.ties.get(d.tieName);if(!d.dataPath)return void console.error("path to data not available");if(!e)return void console.error('tie "'+d.tieName+'" not found');e.viewToDataProcessor({data:e.data,path:d.dataPath,view:b.target})}})}function d(a){"INPUT"!==a.nodeName&&"SELECT"!==a.nodeName||a.addEventListener("change",c)}function e(a){a.removeEventListener("change",c)}function f(b){if("IFRAME"===b.nodeName)n(b.contentDocument),b.addEventListener("load",function(){n(this.contentDocument),h(this.contentDocument)}),h(b.contentDocument);else{a.DataTier.rules.getApplicable(b).forEach(function(a){var c,e,f,h=a.parseParam(b.dataset[a.name]),i=h.dataPath.join(".");o[h.tieName]||(o[h.tieName]={}),c=o[h.tieName],c[a.name]||(c[a.name]={}),e=c[a.name],e[i]||(e[i]=[]),f=e[i],f.indexOf(b)<0&&(f.push(b),g(b,a.name),d(b))});for(var c in b.dataset)0!==c.indexOf("tie")||a.DataTier.rules.get(c)||(console.warn('non-registerd rule "'+c+'" used, it may still be defined later in code and post-tied'),p[c]||(p[c]=[]),p[c].push(b))}}function g(c,d){var e,f,g,h;e=a.DataTier.rules.get(d),f=e.parseParam(c.dataset[d]),g=a.DataTier.ties.get(f.tieName),g&&(h=b(g.data,f.dataPath),e.dataToView(h,c))}function h(a){var b;a&&a.nodeType&&(a.nodeType===Node.DOCUMENT_NODE||a.nodeType===Node.ELEMENT_NODE)&&(b=b="IFRAME"===a.nodeName?Array.from(a.contentDocument.getElementsByTagName("*")):Array.from(a.getElementsByTagName("*")),b.push(a),b.forEach(f))}function i(b){var c,d,f,g;b&&b.getElementsByTagName&&(c=Array.from(b.getElementsByTagName("*")),c.push(b),c.forEach(function(b){a.DataTier.rules.getApplicable(b).forEach(function(a){d=a.parseParam(b.dataset[a.name]),f=o[d.tieName][a.name][d.dataPath.join(".")],g=f.indexOf(b),g>=0&&(f.splice(g,1),e(b))})}))}function j(b,c,d,e){var f,h,i=-1;f=a.DataTier.rules.get(c).parseParam(d),o[f.tieName]&&o[f.tieName][c]&&(h=o[f.tieName][c][f.dataPath],h&&(i=h.indexOf(b)),i>=0&&h.splice(i,1)),f=a.DataTier.rules.get(c).parseParam(e),o[f.tieName]||(o[f.tieName]={}),o[f.tieName][c]||(o[f.tieName][c]={}),o[f.tieName][c][f.dataPath]||(o[f.tieName][c][f.dataPath]=[]),o[f.tieName][c][f.dataPath].push(b),g(b,c)}function k(a,b){var c,d,e=o[a];e?b.forEach(function(a){d=a.path.join("."),Object.keys(e).forEach(function(a){c=e[a],c&&Object.keys(c).forEach(function(b){0!==b.indexOf(d)&&""!==b||c[b].forEach(function(b){g(b,a)})})})}):console.debug('views of tie "'+a+'" are not defined')}function l(a){p[a.name]&&(p[a.name].forEach(function(a){f(a)}),delete p[a.name])}function m(a){var b,c=2,d=a.split("-");for(b=d[1];c<d.length;)b+=d[c][0].toUpperCase()+d[c++].substr(1);return b}function n(a){function b(a){a.forEach(function(a){var b=a.target,c=a.attributeName;"attributes"===a.type&&0===c.indexOf("data-tie")?j(b,m(c),a.oldValue,b.getAttribute(c)):"attributes"===a.type&&"src"===c&&"IFRAME"===b.nodeName?i(b.contentDocument):"childList"===a.type&&(Array.from(a.addedNodes).forEach(function(a){"IFRAME"===a.nodeName?(a.contentDocument&&(n(a.contentDocument),h(a.contentDocument)),a.addEventListener("load",function(){n(this.contentDocument),h(this.contentDocument)})):h(a)}),Array.from(a.removedNodes).forEach(function(a){i("IFRAME"===a.nodeName?a.contentDocument:a)}))})}var c=new MutationObserver(b);c.observe(a,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,characterData:!1,characterDataOldValue:!1})}var o={},p={};Reflect.defineProperty(a.DataTier,"views",{value:{}}),Reflect.defineProperty(a.DataTier.views,"processChanges",{value:k}),Reflect.defineProperty(a.DataTier.views,"applyRule",{value:l}),n(document),h(document)}(this),function(a){"use strict";var b=a.DataTier.rules.add;b("tieValue",{dataToView:function(a,b){b.value=a?a:""}}),b("tieText",{dataToView:function(a,b){b.textContent=a?a.toString():""}}),b("tiePlaceholder",{dataToView:function(a,b){b.placeholder=a?a:""}}),b("tieTooltip",{dataToView:function(a,b){b.title=a?a:""}}),b("tieSrc",{dataToView:function(a,b){b.src=a?a:""}}),b("tieHRef",{dataToView:function(a,b){b.href=a?a:""}}),b("tieDateValue",{dataToView:function(a,b){b.value=a?a.toLocaleString():""}}),b("tieDateText",{dataToView:function(a,b){b.textContent=a?a.toLocaleString():""}}),b("tieClasses",{dataToView:function(a,b){var c=a&&Array.isArray(a)?a:[];Array.from(b.classList).forEach(function(a){b.classList.remove(a)}),c.length&&b.classList.add.apply(b.classList,c)}}),b("tieList",{parseParam:function(a){return this.constructor.prototype.parseParam(a.split(/\s*=>\s*/)[0])},dataToView:function(a,b){function c(a,b){for(var c=Array.from(l.querySelectorAll('[data-list-item-aid="'+b+'"]'));c.length>a;)l.removeChild(c.pop());return c.length}var d,e,f,g,h,i,j,k,l=b.parentNode;if("TEMPLATE"!==b.nodeName)throw new Error("tieList may be defined on template elements only");if(b.dataset.listSourceAid||(b.dataset.listSourceAid=(new Date).getTime()),d=c(a?a.length:0,b.dataset.listSourceAid),a&&d<a.length)if(f=b.dataset.tieList.trim().split(/\s+/),f&&3===f.length&&"=>"===f[1]){for(g=f[2],i=b.ownerDocument,j=i.createDocumentFragment();d<a.length;d++){for(e=i.importNode(b.content,!0),h=Array.prototype.slice.call(e.querySelectorAll("*"),0),h.forEach(function(a){Object.keys(a.dataset).forEach(function(b){0===a.dataset[b].indexOf(g)&&(a.dataset[b]=a.dataset[b].replace(g,f[0]+"."+d))})}),j.appendChild(e),k=j.lastChild;k.nodeType!==Node.ELEMENT_NODE&&null!==k.previousSibling;)k=k.previousSibling;k.dataset.listItemAid=b.dataset.listSourceAid}l.appendChild(j)}else console.error('invalid parameter for "tieList" rule specified')}})}(this); | ||
!function(a){"use strict";function b(b,c,d){function e(c){a.DataTier.views.processChanges(b,c)}var g;Reflect.defineProperty(this,"name",{value:b}),Reflect.defineProperty(this,"data",{get:function(){return g},set:function(c){c&&(f(c),g&&g.revoke());var d=g;g=c,g&&g.observe(e),a.DataTier.views.processChanges(b,[{type:"update",value:g,oldValue:d,path:[]}])}}),h[b]=this,this.data=c}function c(a,c,d){if(e(a),c&&f(c),h[a])throw new Error("existing tie ("+a+") MAY NOT be re-created, use the tie's own APIs to reconfigure it");return new b(a,c,d)}function d(a){a&&h[a]&&(h[a].observable.revoke(),delete h[a])}function e(a){if(!a||"string"!=typeof a)throw new Error("tie name MUST be a non-empty string");if(/\W/.test(a))throw new Error("tie name MUST consist of alphanumerics or underlines ([a-zA-Z0-9_]) ONLY")}function f(a){if(!a||"object"!=typeof a||"function"!=typeof a.observe||"function"!=typeof a.unobserve||"function"!=typeof a.revoke)throw new Error(a+" is not a valid Observable")}function g(a,b,c){var d;if(a){for(d=0;d<b.length-1;d++)a=a[b[d]]||{};a[b[d]]=c}}var h={};b.prototype.viewToDataProcessor=function(a){g(a.data,a.path,a.view.value)},Reflect.defineProperty(a,"DataTier",{value:{}}),Reflect.defineProperty(a.DataTier,"ties",{value:{}}),Reflect.defineProperty(a.DataTier.ties,"get",{value:function(a){return h[a]}}),Reflect.defineProperty(a.DataTier.ties,"create",{value:c}),Reflect.defineProperty(a.DataTier.ties,"remove",{value:d})}(this),function(a){"use strict";function b(a,b){Reflect.defineProperty(this,"name",{value:a}),Reflect.defineProperty(this,"dataToView",{value:b.dataToView}),"function"==typeof b.inputToData&&Reflect.defineProperty(this,"inputToData",{value:b.inputToData}),"function"==typeof b.parseParam&&Reflect.defineProperty(this,"parseParam",{value:b.parseParam})}function c(c,d){if("string"!=typeof c||!c)throw new Error("name MUST be a non-empty string");if(g[c])throw new Error('rule "'+c+'" already exists; you may want to reconfigure the existing rule');if("object"!=typeof d||!d)throw new Error("configuration MUST be a non-null object");if("function"!=typeof d.dataToView)throw new Error('configuration MUST have a "dataToView" function defined');g[c]=new b(c,d),a.DataTier.views.applyRule(g[c])}function d(a){return g[a]}function e(a){if("string"!=typeof a||!a)throw new Error("rule name MUST be a non-empty string");return delete g[a]}function f(a){var b=[];return a&&a.nodeType===Node.ELEMENT_NODE&&a.dataset&&Reflect.ownKeys(a.dataset).forEach(function(a){g[a]&&b.push(g[a])}),b}var g={};b.prototype.parseParam=function(a){var b,c;return a?(b=a.trim().split("."),c=b.shift(),{tieName:c,dataPath:b}):void console.error("valid rule value MUST be a non-empty string, found: "+a)},Reflect.defineProperty(a.DataTier,"rules",{value:{}}),Reflect.defineProperty(a.DataTier.rules,"get",{value:d}),Reflect.defineProperty(a.DataTier.rules,"add",{value:c}),Reflect.defineProperty(a.DataTier.rules,"remove",{value:e}),Reflect.defineProperty(a.DataTier.rules,"getApplicable",{value:f})}(this),function(a){"use strict";function b(a,b){var c;if(a){for(c=0;c<b.length;c++)if(a=a[b[c]],!a)return;return a}}function c(b){a.DataTier.rules.getApplicable(b.target).forEach(function(c){if("tieValue"===c.name){var d=c.parseParam(b.target.dataset[c.name]),e=a.DataTier.ties.get(d.tieName);if(!d.dataPath)return void console.error("path to data not available");if(!e)return void console.error('tie "'+d.tieName+'" not found');e.viewToDataProcessor({data:e.data,path:d.dataPath,view:b.target})}})}function d(a){"INPUT"!==a.nodeName&&"SELECT"!==a.nodeName||a.addEventListener("change",c)}function e(a){a.removeEventListener("change",c)}function f(b){if("IFRAME"===b.nodeName)n(b.contentDocument),b.addEventListener("load",function(){n(this.contentDocument),h(this.contentDocument)}),h(b.contentDocument);else{a.DataTier.rules.getApplicable(b).forEach(function(a){var c,e,f,h=a.parseParam(b.dataset[a.name]),i=h.dataPath.join(".");o[h.tieName]||(o[h.tieName]={}),c=o[h.tieName],c[a.name]||(c[a.name]={}),e=c[a.name],e[i]||(e[i]=[]),f=e[i],f.indexOf(b)<0&&(f.push(b),g(b,a.name),d(b))});for(var c in b.dataset)0!==c.indexOf("tie")||a.DataTier.rules.get(c)||(console.warn('non-registerd rule "'+c+'" used, it may still be defined later in code and post-tied'),p[c]||(p[c]=[]),p[c].push(b))}}function g(c,d){var e,f,g,h;e=a.DataTier.rules.get(d),f=e.parseParam(c.dataset[d]),g=a.DataTier.ties.get(f.tieName),g&&(h=b(g.data,f.dataPath),e.dataToView(h,c))}function h(a){var b;a&&a.nodeType&&(a.nodeType===Node.DOCUMENT_NODE||a.nodeType===Node.ELEMENT_NODE)&&(b=b="IFRAME"===a.nodeName?Array.from(a.contentDocument.getElementsByTagName("*")):Array.from(a.getElementsByTagName("*")),b.push(a),b.forEach(f))}function i(b){var c,d,f,g;b&&b.getElementsByTagName&&(c=Array.from(b.getElementsByTagName("*")),c.push(b),c.forEach(function(b){a.DataTier.rules.getApplicable(b).forEach(function(a){d=a.parseParam(b.dataset[a.name]),f=o[d.tieName][a.name][d.dataPath.join(".")],g=f.indexOf(b),g>=0&&(f.splice(g,1),e(b))})}))}function j(b,c,d,e){var f,h,i=-1;f=a.DataTier.rules.get(c).parseParam(d),o[f.tieName]&&o[f.tieName][c]&&(h=o[f.tieName][c][f.dataPath],h&&(i=h.indexOf(b)),i>=0&&h.splice(i,1)),f=a.DataTier.rules.get(c).parseParam(e),o[f.tieName]||(o[f.tieName]={}),o[f.tieName][c]||(o[f.tieName][c]={}),o[f.tieName][c][f.dataPath]||(o[f.tieName][c][f.dataPath]=[]),o[f.tieName][c][f.dataPath].push(b),g(b,c)}function k(a,b){var c,d,e=o[a];e?b.forEach(function(a){d=a.path.join("."),Object.keys(e).forEach(function(a){c=e[a],c&&Object.keys(c).forEach(function(b){0!==b.indexOf(d)&&""!==b||c[b].forEach(function(b){g(b,a)})})})}):console.debug('views of tie "'+a+'" are not defined')}function l(a){p[a.name]&&(p[a.name].forEach(function(a){f(a)}),delete p[a.name])}function m(a){var b,c=2,d=a.split("-");for(b=d[1];c<d.length;)b+=d[c][0].toUpperCase()+d[c++].substr(1);return b}function n(a){function b(a){a.forEach(function(a){var b=a.target,c=a.attributeName;"attributes"===a.type&&0===c.indexOf("data-tie")?j(b,m(c),a.oldValue,b.getAttribute(c)):"attributes"===a.type&&"src"===c&&"IFRAME"===b.nodeName?i(b.contentDocument):"childList"===a.type&&(Array.from(a.addedNodes).forEach(function(a){"IFRAME"===a.nodeName?(a.contentDocument&&(n(a.contentDocument),h(a.contentDocument)),a.addEventListener("load",function(){n(this.contentDocument),h(this.contentDocument)})):h(a)}),Array.from(a.removedNodes).forEach(function(a){i("IFRAME"===a.nodeName?a.contentDocument:a)}))})}var c=new MutationObserver(b);c.observe(a,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,characterData:!1,characterDataOldValue:!1})}var o={},p={};Reflect.defineProperty(a.DataTier,"views",{value:{}}),Reflect.defineProperty(a.DataTier.views,"processChanges",{value:k}),Reflect.defineProperty(a.DataTier.views,"applyRule",{value:l}),n(document),h(document)}(this),function(a){"use strict";var b=a.DataTier.rules.add;b("tieValue",{dataToView:function(a,b){b.value=a?a:""}}),b("tieText",{dataToView:function(a,b){b.textContent=a?a.toString():""}}),b("tiePlaceholder",{dataToView:function(a,b){b.placeholder=a?a:""}}),b("tieTooltip",{dataToView:function(a,b){b.title=a?a:""}}),b("tieSrc",{dataToView:function(a,b){b.src=a?a:""}}),b("tieHRef",{dataToView:function(a,b){b.href=a?a:""}}),b("tieDateValue",{dataToView:function(a,b){b.value=a?a.toLocaleString():""}}),b("tieDateText",{dataToView:function(a,b){b.textContent=a?a.toLocaleString():""}}),b("tieClasses",{dataToView:function(a,b){var c=a&&Array.isArray(a)?a:[];Array.from(b.classList).forEach(function(a){b.classList.remove(a)}),c.length&&b.classList.add.apply(b.classList,c)}}),b("tieList",{parseParam:function(a){return this.constructor.prototype.parseParam(a.split(/\s*=>\s*/)[0])},dataToView:function(a,b){function c(a,b){for(var c=Array.from(l.querySelectorAll('[data-list-item-aid="'+b+'"]'));c.length>a;)l.removeChild(c.pop());return c.length}var d,e,f,g,h,i,j,k,l=b.parentNode;if("TEMPLATE"!==b.nodeName)throw new Error("tieList may be defined on template elements only");if(b.dataset.listSourceAid||(b.dataset.listSourceAid=(new Date).getTime()),d=c(a?a.length:0,b.dataset.listSourceAid),a&&d<a.length)if(f=b.dataset.tieList.trim().split(/\s+/),f&&3===f.length&&"=>"===f[1]){for(g=f[2],i=b.ownerDocument,j=i.createDocumentFragment();d<a.length;d++){for(e=i.importNode(b.content,!0),h=Array.prototype.slice.call(e.querySelectorAll("*"),0),h.forEach(function(a){Object.keys(a.dataset).forEach(function(b){0===a.dataset[b].indexOf(g)&&(a.dataset[b]=a.dataset[b].replace(g,f[0]+"."+d))})}),j.appendChild(e),k=j.lastChild;k.nodeType!==Node.ELEMENT_NODE&&null!==k.previousSibling;)k=k.previousSibling;k.dataset.listItemAid=b.dataset.listSourceAid}l.appendChild(j)}else console.error('invalid parameter for "tieList" rule specified')}})}(this); |
@@ -501,6 +501,11 @@ (function (scope) { | ||
} | ||
Tie.prototype.viewToDataProcessor = function vanillaViewToDataProcessor(event) { | ||
setPath(event.data, event.path, event.view.value); | ||
}; | ||
function create(name, observable, options) { | ||
validateTieName(name); | ||
validateObservable(observable); | ||
if (observable) { | ||
validateObservable(observable); | ||
} | ||
if (ties[name]) { | ||
@@ -539,2 +544,12 @@ throw new Error('existing tie (' + name + ') MAY NOT be re-created, use the tie\'s own APIs to reconfigure it'); | ||
// TODO: this is similar to getPath in views-service - unify | ||
function setPath(ref, path, value) { | ||
var i; | ||
if (!ref) return; | ||
for (i = 0; i < path.length - 1; i++) { | ||
ref = ref[path[i]] || {}; | ||
} | ||
ref[path[i]] = value; | ||
} | ||
Reflect.defineProperty(scope, 'DataTier', { value: {} }); | ||
@@ -628,2 +643,3 @@ Reflect.defineProperty(scope.DataTier, 'ties', { value: {} }); | ||
// TODO: this is similar to setPath in ties-service - unify | ||
function getPath(ref, path) { | ||
@@ -630,0 +646,0 @@ var i; |
@@ -1,1 +0,1 @@ | ||
!function(a){"use strict";function b(a){var b;return b=Array.isArray(a)?a.slice():Object.assign(new a.constructor,a)}function c(a){return t.indexOf(a.constructor.name)>=0}function d(a,b){var c,d=r.get(a),e=s.get(d.root);return c="pop"===b?function(){var c,f,g;return c=a.length-1,f=Reflect.apply(a[b],a,arguments),f&&"object"==typeof f&&(f=q.get(f),r.get(f).revoke()),g=[new m(d.path.concat(c),f)],p(e.callbacks,g),f}:"push"===b?function(){var c,f,g,h=[];return c=Array.from(arguments),g=a.length,c.forEach(function(a,b){a&&"object"==typeof a&&(c[b]=new i(a,g+b,d).proxy),h.push(new k(d.path.concat(g+b),a))}),f=Reflect.apply(a[b],a,c),p(e.callbacks,h),f}:"shift"===b?function(){var c,f,g;return c=Reflect.apply(a[b],a,arguments),c&&"object"==typeof c&&(c=q.get(c),r.get(c).revoke()),a.forEach(function(a,b){a&&"object"==typeof a&&(g=r.get(q.get(a)),g?g.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))}),f=[new m(d.path.concat(0),c)],p(e.callbacks,f),c}:"unshift"===b?function(){var c,f,g,h=[];c=Array.from(arguments),c.forEach(function(a,b){a&&"object"==typeof a&&(c[b]=new i(a,b,d).proxy)}),f=Reflect.apply(a[b],a,c),a.forEach(function(a,b){a&&"object"==typeof a&&(g=r.get(q.get(a)),g?g.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))});for(var j=0;j<c.length;j++)h.push(new k(d.path.concat(j),a[j]));return p(e.callbacks,h),f}:"reverse"===b?function(){var c,d=[];return Reflect.apply(a[b],a,arguments),a.forEach(function(a,b){a&&"object"==typeof a&&(c=r.get(q.get(a)),c?c.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))}),d.push(new n),p(e.callbacks,d),this}:"sort"===b?function(){var c,d=[];return Reflect.apply(a[b],a,arguments),a.forEach(function(a,b){a&&"object"==typeof a&&(c=r.get(q.get(a)),c?c.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))}),d.push(new o),p(e.callbacks,d),this}:"fill"===b?function(){var c,f,g,h=[];c=arguments.length<2?0:arguments[1]<0?a.length+arguments[1]:arguments[1],f=arguments.length<3?a.length:arguments[2]<0?a.length+arguments[2]:arguments[2],g=a.slice(),Reflect.apply(a[b],a,arguments);for(var j=c;j<f;j++)a[j]&&"object"==typeof a[j]&&(a[j]=new i(a[j],j,d).proxy),g.hasOwnProperty(j)?(h.push(new l(d.path.concat(j),a[j],g[j]&&"object"==typeof g[j]?q.get(g[j]):g[j])),g[j]&&"object"==typeof g[j]&&r.get(q.get(g[j])).revoke()):h.push(new k(d.path.concat(j),a[j]));return p(e.callbacks,h),this}:"splice"===b?function(){var c,f,g,h,j,n,o,s=[];for(c=Array.from(arguments),c.forEach(function(a,b){b>1&&a&&"object"==typeof a&&(c[b]=new i(a,b,d).proxy)}),j=0===c.length?0:c[0]<0?a.length+c[0]:c[0],n=c.length<2?a.length-j:c[1],o=Math.max(c.length-2,0),f=Reflect.apply(a[b],a,c),a.forEach(function(a,b){a&&"object"==typeof a&&(g=r.get(q.get(a)),g?g.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))}),f.forEach(function(a,b){a&&"object"==typeof a&&(f[b]=q.get(a),r.get(f[b]).revoke())}),h=0;h<n;h++)h<o?s.push(new l(d.path.concat(j+h),a[j+h],f[h])):s.push(new m(d.path.concat(j+h),f[h]));for(;h<o;h++)s.push(new k(d.path.concat(j+h),a[j+h]));return p(e.callbacks,s),f}:Reflect.get(a,b)}function e(a,b,c){var d,e,f=a.hasOwnProperty(b),g=a[b],h=r.get(a),j=s.get(h.root),m=[];return d=Reflect.set(a,b,c),j.callbacks.length&&d&&c!==g&&(e=h.path.concat(b),g&&"object"==typeof g&&(r.get(q.get(g)).revoke(),q.has(g)&&q.delete(g)),c&&"object"==typeof c&&(a[b]=new i(c,b,h).proxy),f?m.push(new l(e,c,g)):m.push(new k(e,c)),h.preventCallbacks||p(j.callbacks,m)),d}function f(a,b){var c,d,e=a[b],f=r.get(a),g=s.get(f.root),h=[];return c=Reflect.deleteProperty(a,b),g.callbacks.length&&c&&("object"==typeof e&&e&&q.has(e)&&q.delete(e),d=f.path.concat(b),h.push(new m(d,e)),f.preventCallbacks||p(g.callbacks,h)),c}function g(a,b){a.forEach(function(d,e){d&&"object"==typeof d&&!c(d)&&(a[e]=new i(d,e,b).proxy)})}function h(a,b){Reflect.ownKeys(a).forEach(function(d){a[d]&&"object"==typeof a[d]&&!c(a[d])&&(a[d]=new i(a[d],d,b).proxy)})}function i(a,c,j){var k,l;if(!a||"object"!=typeof a)throw new Error("Observed MUST be created from a non null object origin");if(j&&("undefined"==typeof c||null===c))throw new Error("any non-root (parent-less) Observed MUST have an own path; now parent is "+j+"; key is "+c);if(j&&!(j instanceof i))throw new Error("parent, when supplied, MUST be an instance of Observed");k=b(a),Array.isArray(k)?(g(k,this),l=Proxy.revocable(k,{set:e,get:d,deleteProperty:f})):(h(k,this),l=Proxy.revocable(k,{set:e,deleteProperty:f})),r.set(k,this),q.set(l.proxy,k),Reflect.defineProperty(this,"revokable",{value:l}),Reflect.defineProperty(this,"proxy",{value:l.proxy}),Reflect.defineProperty(this,"parent",{value:j}),Reflect.defineProperty(this,"ownKey",{value:c,writable:!0})}function j(a){function b(a){if(e)throw new TypeError("revoked Observable MAY NOT be observed anymore");if("function"!=typeof a)throw new Error("observer (callback) parameter MUST be a function");f.indexOf(a)<0?f.push(a):console.info("observer (callback) may be bound to an observable only once")}function c(){if(e)throw new TypeError("revoked Observable MAY NOT be unobserved amymore");arguments.length?Array.from(arguments).forEach(function(a){var b=f.indexOf(a);b>=0&&f.splice(b,1)}):f.splice(0,f.length)}function d(){e?console.log("revokation of Observable have an effect only once"):(e=!0,a.revoke())}var e=!1,f=[];Reflect.defineProperty(a.proxy,"observe",{value:b}),Reflect.defineProperty(a.proxy,"unobserve",{value:c}),Reflect.defineProperty(a.proxy,"revoke",{value:d}),Reflect.defineProperty(this,"callbacks",{value:f})}function k(a,b){Reflect.defineProperty(this,"type",{value:"insert"}),Reflect.defineProperty(this,"path",{value:a}),Reflect.defineProperty(this,"value",{value:b})}function l(a,b,c){Reflect.defineProperty(this,"type",{value:"update"}),Reflect.defineProperty(this,"path",{value:a}),Reflect.defineProperty(this,"value",{value:b}),Reflect.defineProperty(this,"oldValue",{value:c})}function m(a,b){Reflect.defineProperty(this,"type",{value:"delete"}),Reflect.defineProperty(this,"path",{value:a}),Reflect.defineProperty(this,"oldValue",{value:b})}function n(){Reflect.defineProperty(this,"type",{value:"reverse"})}function o(){Reflect.defineProperty(this,"type",{value:"shuffle"})}function p(a,b){for(var c=0;c<a.length;c++)try{a[c](b)}catch(a){console.error(a)}}var q=new Map,r=new Map,s=new Map,t=["Date","Blob","Number","String","Boolean","Error","SyntaxError","TypeError","URIError","Function","Promise","RegExp"];Reflect.defineProperty(i.prototype,"root",{get:function(){for(var a=this;a.parent;)a=a.parent;return a}}),Reflect.defineProperty(i.prototype,"path",{get:function(){for(var a=[],b=this;"undefined"!=typeof b.ownKey;)a.push(b.ownKey),b=b.parent;return a.reverse()}}),Reflect.defineProperty(i.prototype,"revoke",{value:function(){var a=this.proxy;Reflect.ownKeys(a).forEach(function(b){var c=a[b];c&&"object"==typeof c&&(r.get(q.get(c)).revoke(),q.get(a)[b]=q.get(c))}),this.revokable.revoke()}}),Reflect.defineProperty(j,"from",{value:function(a){if(!a||"object"!=typeof a)throw new Error("observable MAY ONLY be created from non-null object only");if("observe"in a||"unobserve"in a||"revoke"in a)throw new Error('target object MUST NOT have nor own neither inherited properties from the following list: "observe", "unobserve", "revoke"');if(c(a))throw new Error(a+" found to be one of non-observable object types: "+t);var b=new i(a),d=new j(b);return s.set(b,d),b.proxy}}),Reflect.defineProperty(a,"Observable",{value:j})}(this),function(a){"use strict";function b(b,c,d){function e(c){a.DataTier.views.processChanges(b,c)}var h;Reflect.defineProperty(this,"name",{value:b}),Reflect.defineProperty(this,"data",{get:function(){return h},set:function(c){c&&(f(c),h&&h.revoke());var d=h;h=c,h&&h.observe(e),a.DataTier.views.processChanges(b,[{type:"update",value:h,oldValue:d,path:[]}])}}),g[b]=this,this.data=c}function c(a,c,d){if(e(a),f(c),g[a])throw new Error("existing tie ("+a+") MAY NOT be re-created, use the tie's own APIs to reconfigure it");return new b(a,c,d)}function d(a){a&&g[a]&&(g[a].observable.revoke(),delete g[a])}function e(a){if(!a||"string"!=typeof a)throw new Error("tie name MUST be a non-empty string");if(/\W/.test(a))throw new Error("tie name MUST consist of alphanumerics or underlines ([a-zA-Z0-9_]) ONLY")}function f(a){if(!a||"object"!=typeof a||"function"!=typeof a.observe||"function"!=typeof a.unobserve||"function"!=typeof a.revoke)throw new Error(a+" is not a valid Observable")}var g={};Reflect.defineProperty(a,"DataTier",{value:{}}),Reflect.defineProperty(a.DataTier,"ties",{value:{}}),Reflect.defineProperty(a.DataTier.ties,"get",{value:function(a){return g[a]}}),Reflect.defineProperty(a.DataTier.ties,"create",{value:c}),Reflect.defineProperty(a.DataTier.ties,"remove",{value:d})}(this),function(a){"use strict";function b(a,b){Reflect.defineProperty(this,"name",{value:a}),Reflect.defineProperty(this,"dataToView",{value:b.dataToView}),"function"==typeof b.inputToData&&Reflect.defineProperty(this,"inputToData",{value:b.inputToData}),"function"==typeof b.parseParam&&Reflect.defineProperty(this,"parseParam",{value:b.parseParam})}function c(c,d){if("string"!=typeof c||!c)throw new Error("name MUST be a non-empty string");if(g[c])throw new Error('rule "'+c+'" already exists; you may want to reconfigure the existing rule');if("object"!=typeof d||!d)throw new Error("configuration MUST be a non-null object");if("function"!=typeof d.dataToView)throw new Error('configuration MUST have a "dataToView" function defined');g[c]=new b(c,d),a.DataTier.views.applyRule(g[c])}function d(a){return g[a]}function e(a){if("string"!=typeof a||!a)throw new Error("rule name MUST be a non-empty string");return delete g[a]}function f(a){var b=[];return a&&a.nodeType===Node.ELEMENT_NODE&&a.dataset&&Reflect.ownKeys(a.dataset).forEach(function(a){g[a]&&b.push(g[a])}),b}var g={};b.prototype.parseParam=function(a){var b,c;return a?(b=a.trim().split("."),c=b.shift(),{tieName:c,dataPath:b}):void console.error("valid rule value MUST be a non-empty string, found: "+a)},Reflect.defineProperty(a.DataTier,"rules",{value:{}}),Reflect.defineProperty(a.DataTier.rules,"get",{value:d}),Reflect.defineProperty(a.DataTier.rules,"add",{value:c}),Reflect.defineProperty(a.DataTier.rules,"remove",{value:e}),Reflect.defineProperty(a.DataTier.rules,"getApplicable",{value:f})}(this),function(a){"use strict";function b(a,b){var c;if(a){for(c=0;c<b.length;c++)if(a=a[b[c]],!a)return;return a}}function c(b){a.DataTier.rules.getApplicable(b.target).forEach(function(c){if("tieValue"===c.name){var d=c.parseParam(b.target.dataset[c.name]),e=a.DataTier.ties.get(d.tieName);if(!d.dataPath)return void console.error("path to data not available");if(!e)return void console.error('tie "'+d.tieName+'" not found');e.viewToDataProcessor({data:e.data,path:d.dataPath,view:b.target})}})}function d(a){"INPUT"!==a.nodeName&&"SELECT"!==a.nodeName||a.addEventListener("change",c)}function e(a){a.removeEventListener("change",c)}function f(b){if("IFRAME"===b.nodeName)n(b.contentDocument),b.addEventListener("load",function(){n(this.contentDocument),h(this.contentDocument)}),h(b.contentDocument);else{a.DataTier.rules.getApplicable(b).forEach(function(a){var c,e,f,h=a.parseParam(b.dataset[a.name]),i=h.dataPath.join(".");o[h.tieName]||(o[h.tieName]={}),c=o[h.tieName],c[a.name]||(c[a.name]={}),e=c[a.name],e[i]||(e[i]=[]),f=e[i],f.indexOf(b)<0&&(f.push(b),g(b,a.name),d(b))});for(var c in b.dataset)0!==c.indexOf("tie")||a.DataTier.rules.get(c)||(console.warn('non-registerd rule "'+c+'" used, it may still be defined later in code and post-tied'),p[c]||(p[c]=[]),p[c].push(b))}}function g(c,d){var e,f,g,h;e=a.DataTier.rules.get(d),f=e.parseParam(c.dataset[d]),g=a.DataTier.ties.get(f.tieName),g&&(h=b(g.data,f.dataPath),e.dataToView(h,c))}function h(a){var b;a&&a.nodeType&&(a.nodeType===Node.DOCUMENT_NODE||a.nodeType===Node.ELEMENT_NODE)&&(b=b="IFRAME"===a.nodeName?Array.from(a.contentDocument.getElementsByTagName("*")):Array.from(a.getElementsByTagName("*")),b.push(a),b.forEach(f))}function i(b){var c,d,f,g;b&&b.getElementsByTagName&&(c=Array.from(b.getElementsByTagName("*")),c.push(b),c.forEach(function(b){a.DataTier.rules.getApplicable(b).forEach(function(a){d=a.parseParam(b.dataset[a.name]),f=o[d.tieName][a.name][d.dataPath.join(".")],g=f.indexOf(b),g>=0&&(f.splice(g,1),e(b))})}))}function j(b,c,d,e){var f,h,i=-1;f=a.DataTier.rules.get(c).parseParam(d),o[f.tieName]&&o[f.tieName][c]&&(h=o[f.tieName][c][f.dataPath],h&&(i=h.indexOf(b)),i>=0&&h.splice(i,1)),f=a.DataTier.rules.get(c).parseParam(e),o[f.tieName]||(o[f.tieName]={}),o[f.tieName][c]||(o[f.tieName][c]={}),o[f.tieName][c][f.dataPath]||(o[f.tieName][c][f.dataPath]=[]),o[f.tieName][c][f.dataPath].push(b),g(b,c)}function k(a,b){var c,d,e=o[a];e?b.forEach(function(a){d=a.path.join("."),Object.keys(e).forEach(function(a){c=e[a],c&&Object.keys(c).forEach(function(b){0!==b.indexOf(d)&&""!==b||c[b].forEach(function(b){g(b,a)})})})}):console.debug('views of tie "'+a+'" are not defined')}function l(a){p[a.name]&&(p[a.name].forEach(function(a){f(a)}),delete p[a.name])}function m(a){var b,c=2,d=a.split("-");for(b=d[1];c<d.length;)b+=d[c][0].toUpperCase()+d[c++].substr(1);return b}function n(a){function b(a){a.forEach(function(a){var b=a.target,c=a.attributeName;"attributes"===a.type&&0===c.indexOf("data-tie")?j(b,m(c),a.oldValue,b.getAttribute(c)):"attributes"===a.type&&"src"===c&&"IFRAME"===b.nodeName?i(b.contentDocument):"childList"===a.type&&(Array.from(a.addedNodes).forEach(function(a){"IFRAME"===a.nodeName?(a.contentDocument&&(n(a.contentDocument),h(a.contentDocument)),a.addEventListener("load",function(){n(this.contentDocument),h(this.contentDocument)})):h(a)}),Array.from(a.removedNodes).forEach(function(a){i("IFRAME"===a.nodeName?a.contentDocument:a)}))})}var c=new MutationObserver(b);c.observe(a,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,characterData:!1,characterDataOldValue:!1})}var o={},p={};Reflect.defineProperty(a.DataTier,"views",{value:{}}),Reflect.defineProperty(a.DataTier.views,"processChanges",{value:k}),Reflect.defineProperty(a.DataTier.views,"applyRule",{value:l}),n(document),h(document)}(this),function(a){"use strict";var b=a.DataTier.rules.add;b("tieValue",{dataToView:function(a,b){b.value=a?a:""}}),b("tieText",{dataToView:function(a,b){b.textContent=a?a.toString():""}}),b("tiePlaceholder",{dataToView:function(a,b){b.placeholder=a?a:""}}),b("tieTooltip",{dataToView:function(a,b){b.title=a?a:""}}),b("tieSrc",{dataToView:function(a,b){b.src=a?a:""}}),b("tieHRef",{dataToView:function(a,b){b.href=a?a:""}}),b("tieDateValue",{dataToView:function(a,b){b.value=a?a.toLocaleString():""}}),b("tieDateText",{dataToView:function(a,b){b.textContent=a?a.toLocaleString():""}}),b("tieClasses",{dataToView:function(a,b){var c=a&&Array.isArray(a)?a:[];Array.from(b.classList).forEach(function(a){b.classList.remove(a)}),c.length&&b.classList.add.apply(b.classList,c)}}),b("tieList",{parseParam:function(a){return this.constructor.prototype.parseParam(a.split(/\s*=>\s*/)[0])},dataToView:function(a,b){function c(a,b){for(var c=Array.from(l.querySelectorAll('[data-list-item-aid="'+b+'"]'));c.length>a;)l.removeChild(c.pop());return c.length}var d,e,f,g,h,i,j,k,l=b.parentNode;if("TEMPLATE"!==b.nodeName)throw new Error("tieList may be defined on template elements only");if(b.dataset.listSourceAid||(b.dataset.listSourceAid=(new Date).getTime()),d=c(a?a.length:0,b.dataset.listSourceAid),a&&d<a.length)if(f=b.dataset.tieList.trim().split(/\s+/),f&&3===f.length&&"=>"===f[1]){for(g=f[2],i=b.ownerDocument,j=i.createDocumentFragment();d<a.length;d++){for(e=i.importNode(b.content,!0),h=Array.prototype.slice.call(e.querySelectorAll("*"),0),h.forEach(function(a){Object.keys(a.dataset).forEach(function(b){0===a.dataset[b].indexOf(g)&&(a.dataset[b]=a.dataset[b].replace(g,f[0]+"."+d))})}),j.appendChild(e),k=j.lastChild;k.nodeType!==Node.ELEMENT_NODE&&null!==k.previousSibling;)k=k.previousSibling;k.dataset.listItemAid=b.dataset.listSourceAid}l.appendChild(j)}else console.error('invalid parameter for "tieList" rule specified')}})}(this); | ||
!function(a){"use strict";function b(a){var b;return b=Array.isArray(a)?a.slice():Object.assign(new a.constructor,a)}function c(a){return t.indexOf(a.constructor.name)>=0}function d(a,b){var c,d=r.get(a),e=s.get(d.root);return c="pop"===b?function(){var c,f,g;return c=a.length-1,f=Reflect.apply(a[b],a,arguments),f&&"object"==typeof f&&(f=q.get(f),r.get(f).revoke()),g=[new m(d.path.concat(c),f)],p(e.callbacks,g),f}:"push"===b?function(){var c,f,g,h=[];return c=Array.from(arguments),g=a.length,c.forEach(function(a,b){a&&"object"==typeof a&&(c[b]=new i(a,g+b,d).proxy),h.push(new k(d.path.concat(g+b),a))}),f=Reflect.apply(a[b],a,c),p(e.callbacks,h),f}:"shift"===b?function(){var c,f,g;return c=Reflect.apply(a[b],a,arguments),c&&"object"==typeof c&&(c=q.get(c),r.get(c).revoke()),a.forEach(function(a,b){a&&"object"==typeof a&&(g=r.get(q.get(a)),g?g.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))}),f=[new m(d.path.concat(0),c)],p(e.callbacks,f),c}:"unshift"===b?function(){var c,f,g,h=[];c=Array.from(arguments),c.forEach(function(a,b){a&&"object"==typeof a&&(c[b]=new i(a,b,d).proxy)}),f=Reflect.apply(a[b],a,c),a.forEach(function(a,b){a&&"object"==typeof a&&(g=r.get(q.get(a)),g?g.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))});for(var j=0;j<c.length;j++)h.push(new k(d.path.concat(j),a[j]));return p(e.callbacks,h),f}:"reverse"===b?function(){var c,d=[];return Reflect.apply(a[b],a,arguments),a.forEach(function(a,b){a&&"object"==typeof a&&(c=r.get(q.get(a)),c?c.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))}),d.push(new n),p(e.callbacks,d),this}:"sort"===b?function(){var c,d=[];return Reflect.apply(a[b],a,arguments),a.forEach(function(a,b){a&&"object"==typeof a&&(c=r.get(q.get(a)),c?c.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))}),d.push(new o),p(e.callbacks,d),this}:"fill"===b?function(){var c,f,g,h=[];c=arguments.length<2?0:arguments[1]<0?a.length+arguments[1]:arguments[1],f=arguments.length<3?a.length:arguments[2]<0?a.length+arguments[2]:arguments[2],g=a.slice(),Reflect.apply(a[b],a,arguments);for(var j=c;j<f;j++)a[j]&&"object"==typeof a[j]&&(a[j]=new i(a[j],j,d).proxy),g.hasOwnProperty(j)?(h.push(new l(d.path.concat(j),a[j],g[j]&&"object"==typeof g[j]?q.get(g[j]):g[j])),g[j]&&"object"==typeof g[j]&&r.get(q.get(g[j])).revoke()):h.push(new k(d.path.concat(j),a[j]));return p(e.callbacks,h),this}:"splice"===b?function(){var c,f,g,h,j,n,o,s=[];for(c=Array.from(arguments),c.forEach(function(a,b){b>1&&a&&"object"==typeof a&&(c[b]=new i(a,b,d).proxy)}),j=0===c.length?0:c[0]<0?a.length+c[0]:c[0],n=c.length<2?a.length-j:c[1],o=Math.max(c.length-2,0),f=Reflect.apply(a[b],a,c),a.forEach(function(a,b){a&&"object"==typeof a&&(g=r.get(q.get(a)),g?g.ownKey=b:console.error("failed to resolve proxy -> target -> observed"))}),f.forEach(function(a,b){a&&"object"==typeof a&&(f[b]=q.get(a),r.get(f[b]).revoke())}),h=0;h<n;h++)h<o?s.push(new l(d.path.concat(j+h),a[j+h],f[h])):s.push(new m(d.path.concat(j+h),f[h]));for(;h<o;h++)s.push(new k(d.path.concat(j+h),a[j+h]));return p(e.callbacks,s),f}:Reflect.get(a,b)}function e(a,b,c){var d,e,f=a.hasOwnProperty(b),g=a[b],h=r.get(a),j=s.get(h.root),m=[];return d=Reflect.set(a,b,c),j.callbacks.length&&d&&c!==g&&(e=h.path.concat(b),g&&"object"==typeof g&&(r.get(q.get(g)).revoke(),q.has(g)&&q.delete(g)),c&&"object"==typeof c&&(a[b]=new i(c,b,h).proxy),f?m.push(new l(e,c,g)):m.push(new k(e,c)),h.preventCallbacks||p(j.callbacks,m)),d}function f(a,b){var c,d,e=a[b],f=r.get(a),g=s.get(f.root),h=[];return c=Reflect.deleteProperty(a,b),g.callbacks.length&&c&&("object"==typeof e&&e&&q.has(e)&&q.delete(e),d=f.path.concat(b),h.push(new m(d,e)),f.preventCallbacks||p(g.callbacks,h)),c}function g(a,b){a.forEach(function(d,e){d&&"object"==typeof d&&!c(d)&&(a[e]=new i(d,e,b).proxy)})}function h(a,b){Reflect.ownKeys(a).forEach(function(d){a[d]&&"object"==typeof a[d]&&!c(a[d])&&(a[d]=new i(a[d],d,b).proxy)})}function i(a,c,j){var k,l;if(!a||"object"!=typeof a)throw new Error("Observed MUST be created from a non null object origin");if(j&&("undefined"==typeof c||null===c))throw new Error("any non-root (parent-less) Observed MUST have an own path; now parent is "+j+"; key is "+c);if(j&&!(j instanceof i))throw new Error("parent, when supplied, MUST be an instance of Observed");k=b(a),Array.isArray(k)?(g(k,this),l=Proxy.revocable(k,{set:e,get:d,deleteProperty:f})):(h(k,this),l=Proxy.revocable(k,{set:e,deleteProperty:f})),r.set(k,this),q.set(l.proxy,k),Reflect.defineProperty(this,"revokable",{value:l}),Reflect.defineProperty(this,"proxy",{value:l.proxy}),Reflect.defineProperty(this,"parent",{value:j}),Reflect.defineProperty(this,"ownKey",{value:c,writable:!0})}function j(a){function b(a){if(e)throw new TypeError("revoked Observable MAY NOT be observed anymore");if("function"!=typeof a)throw new Error("observer (callback) parameter MUST be a function");f.indexOf(a)<0?f.push(a):console.info("observer (callback) may be bound to an observable only once")}function c(){if(e)throw new TypeError("revoked Observable MAY NOT be unobserved amymore");arguments.length?Array.from(arguments).forEach(function(a){var b=f.indexOf(a);b>=0&&f.splice(b,1)}):f.splice(0,f.length)}function d(){e?console.log("revokation of Observable have an effect only once"):(e=!0,a.revoke())}var e=!1,f=[];Reflect.defineProperty(a.proxy,"observe",{value:b}),Reflect.defineProperty(a.proxy,"unobserve",{value:c}),Reflect.defineProperty(a.proxy,"revoke",{value:d}),Reflect.defineProperty(this,"callbacks",{value:f})}function k(a,b){Reflect.defineProperty(this,"type",{value:"insert"}),Reflect.defineProperty(this,"path",{value:a}),Reflect.defineProperty(this,"value",{value:b})}function l(a,b,c){Reflect.defineProperty(this,"type",{value:"update"}),Reflect.defineProperty(this,"path",{value:a}),Reflect.defineProperty(this,"value",{value:b}),Reflect.defineProperty(this,"oldValue",{value:c})}function m(a,b){Reflect.defineProperty(this,"type",{value:"delete"}),Reflect.defineProperty(this,"path",{value:a}),Reflect.defineProperty(this,"oldValue",{value:b})}function n(){Reflect.defineProperty(this,"type",{value:"reverse"})}function o(){Reflect.defineProperty(this,"type",{value:"shuffle"})}function p(a,b){for(var c=0;c<a.length;c++)try{a[c](b)}catch(a){console.error(a)}}var q=new Map,r=new Map,s=new Map,t=["Date","Blob","Number","String","Boolean","Error","SyntaxError","TypeError","URIError","Function","Promise","RegExp"];Reflect.defineProperty(i.prototype,"root",{get:function(){for(var a=this;a.parent;)a=a.parent;return a}}),Reflect.defineProperty(i.prototype,"path",{get:function(){for(var a=[],b=this;"undefined"!=typeof b.ownKey;)a.push(b.ownKey),b=b.parent;return a.reverse()}}),Reflect.defineProperty(i.prototype,"revoke",{value:function(){var a=this.proxy;Reflect.ownKeys(a).forEach(function(b){var c=a[b];c&&"object"==typeof c&&(r.get(q.get(c)).revoke(),q.get(a)[b]=q.get(c))}),this.revokable.revoke()}}),Reflect.defineProperty(j,"from",{value:function(a){if(!a||"object"!=typeof a)throw new Error("observable MAY ONLY be created from non-null object only");if("observe"in a||"unobserve"in a||"revoke"in a)throw new Error('target object MUST NOT have nor own neither inherited properties from the following list: "observe", "unobserve", "revoke"');if(c(a))throw new Error(a+" found to be one of non-observable object types: "+t);var b=new i(a),d=new j(b);return s.set(b,d),b.proxy}}),Reflect.defineProperty(a,"Observable",{value:j})}(this),function(a){"use strict";function b(b,c,d){function e(c){a.DataTier.views.processChanges(b,c)}var g;Reflect.defineProperty(this,"name",{value:b}),Reflect.defineProperty(this,"data",{get:function(){return g},set:function(c){c&&(f(c),g&&g.revoke());var d=g;g=c,g&&g.observe(e),a.DataTier.views.processChanges(b,[{type:"update",value:g,oldValue:d,path:[]}])}}),h[b]=this,this.data=c}function c(a,c,d){if(e(a),c&&f(c),h[a])throw new Error("existing tie ("+a+") MAY NOT be re-created, use the tie's own APIs to reconfigure it");return new b(a,c,d)}function d(a){a&&h[a]&&(h[a].observable.revoke(),delete h[a])}function e(a){if(!a||"string"!=typeof a)throw new Error("tie name MUST be a non-empty string");if(/\W/.test(a))throw new Error("tie name MUST consist of alphanumerics or underlines ([a-zA-Z0-9_]) ONLY")}function f(a){if(!a||"object"!=typeof a||"function"!=typeof a.observe||"function"!=typeof a.unobserve||"function"!=typeof a.revoke)throw new Error(a+" is not a valid Observable")}function g(a,b,c){var d;if(a){for(d=0;d<b.length-1;d++)a=a[b[d]]||{};a[b[d]]=c}}var h={};b.prototype.viewToDataProcessor=function(a){g(a.data,a.path,a.view.value)},Reflect.defineProperty(a,"DataTier",{value:{}}),Reflect.defineProperty(a.DataTier,"ties",{value:{}}),Reflect.defineProperty(a.DataTier.ties,"get",{value:function(a){return h[a]}}),Reflect.defineProperty(a.DataTier.ties,"create",{value:c}),Reflect.defineProperty(a.DataTier.ties,"remove",{value:d})}(this),function(a){"use strict";function b(a,b){Reflect.defineProperty(this,"name",{value:a}),Reflect.defineProperty(this,"dataToView",{value:b.dataToView}),"function"==typeof b.inputToData&&Reflect.defineProperty(this,"inputToData",{value:b.inputToData}),"function"==typeof b.parseParam&&Reflect.defineProperty(this,"parseParam",{value:b.parseParam})}function c(c,d){if("string"!=typeof c||!c)throw new Error("name MUST be a non-empty string");if(g[c])throw new Error('rule "'+c+'" already exists; you may want to reconfigure the existing rule');if("object"!=typeof d||!d)throw new Error("configuration MUST be a non-null object");if("function"!=typeof d.dataToView)throw new Error('configuration MUST have a "dataToView" function defined');g[c]=new b(c,d),a.DataTier.views.applyRule(g[c])}function d(a){return g[a]}function e(a){if("string"!=typeof a||!a)throw new Error("rule name MUST be a non-empty string");return delete g[a]}function f(a){var b=[];return a&&a.nodeType===Node.ELEMENT_NODE&&a.dataset&&Reflect.ownKeys(a.dataset).forEach(function(a){g[a]&&b.push(g[a])}),b}var g={};b.prototype.parseParam=function(a){var b,c;return a?(b=a.trim().split("."),c=b.shift(),{tieName:c,dataPath:b}):void console.error("valid rule value MUST be a non-empty string, found: "+a)},Reflect.defineProperty(a.DataTier,"rules",{value:{}}),Reflect.defineProperty(a.DataTier.rules,"get",{value:d}),Reflect.defineProperty(a.DataTier.rules,"add",{value:c}),Reflect.defineProperty(a.DataTier.rules,"remove",{value:e}),Reflect.defineProperty(a.DataTier.rules,"getApplicable",{value:f})}(this),function(a){"use strict";function b(a,b){var c;if(a){for(c=0;c<b.length;c++)if(a=a[b[c]],!a)return;return a}}function c(b){a.DataTier.rules.getApplicable(b.target).forEach(function(c){if("tieValue"===c.name){var d=c.parseParam(b.target.dataset[c.name]),e=a.DataTier.ties.get(d.tieName);if(!d.dataPath)return void console.error("path to data not available");if(!e)return void console.error('tie "'+d.tieName+'" not found');e.viewToDataProcessor({data:e.data,path:d.dataPath,view:b.target})}})}function d(a){"INPUT"!==a.nodeName&&"SELECT"!==a.nodeName||a.addEventListener("change",c)}function e(a){a.removeEventListener("change",c)}function f(b){if("IFRAME"===b.nodeName)n(b.contentDocument),b.addEventListener("load",function(){n(this.contentDocument),h(this.contentDocument)}),h(b.contentDocument);else{a.DataTier.rules.getApplicable(b).forEach(function(a){var c,e,f,h=a.parseParam(b.dataset[a.name]),i=h.dataPath.join(".");o[h.tieName]||(o[h.tieName]={}),c=o[h.tieName],c[a.name]||(c[a.name]={}),e=c[a.name],e[i]||(e[i]=[]),f=e[i],f.indexOf(b)<0&&(f.push(b),g(b,a.name),d(b))});for(var c in b.dataset)0!==c.indexOf("tie")||a.DataTier.rules.get(c)||(console.warn('non-registerd rule "'+c+'" used, it may still be defined later in code and post-tied'),p[c]||(p[c]=[]),p[c].push(b))}}function g(c,d){var e,f,g,h;e=a.DataTier.rules.get(d),f=e.parseParam(c.dataset[d]),g=a.DataTier.ties.get(f.tieName),g&&(h=b(g.data,f.dataPath),e.dataToView(h,c))}function h(a){var b;a&&a.nodeType&&(a.nodeType===Node.DOCUMENT_NODE||a.nodeType===Node.ELEMENT_NODE)&&(b=b="IFRAME"===a.nodeName?Array.from(a.contentDocument.getElementsByTagName("*")):Array.from(a.getElementsByTagName("*")),b.push(a),b.forEach(f))}function i(b){var c,d,f,g;b&&b.getElementsByTagName&&(c=Array.from(b.getElementsByTagName("*")),c.push(b),c.forEach(function(b){a.DataTier.rules.getApplicable(b).forEach(function(a){d=a.parseParam(b.dataset[a.name]),f=o[d.tieName][a.name][d.dataPath.join(".")],g=f.indexOf(b),g>=0&&(f.splice(g,1),e(b))})}))}function j(b,c,d,e){var f,h,i=-1;f=a.DataTier.rules.get(c).parseParam(d),o[f.tieName]&&o[f.tieName][c]&&(h=o[f.tieName][c][f.dataPath],h&&(i=h.indexOf(b)),i>=0&&h.splice(i,1)),f=a.DataTier.rules.get(c).parseParam(e),o[f.tieName]||(o[f.tieName]={}),o[f.tieName][c]||(o[f.tieName][c]={}),o[f.tieName][c][f.dataPath]||(o[f.tieName][c][f.dataPath]=[]),o[f.tieName][c][f.dataPath].push(b),g(b,c)}function k(a,b){var c,d,e=o[a];e?b.forEach(function(a){d=a.path.join("."),Object.keys(e).forEach(function(a){c=e[a],c&&Object.keys(c).forEach(function(b){0!==b.indexOf(d)&&""!==b||c[b].forEach(function(b){g(b,a)})})})}):console.debug('views of tie "'+a+'" are not defined')}function l(a){p[a.name]&&(p[a.name].forEach(function(a){f(a)}),delete p[a.name])}function m(a){var b,c=2,d=a.split("-");for(b=d[1];c<d.length;)b+=d[c][0].toUpperCase()+d[c++].substr(1);return b}function n(a){function b(a){a.forEach(function(a){var b=a.target,c=a.attributeName;"attributes"===a.type&&0===c.indexOf("data-tie")?j(b,m(c),a.oldValue,b.getAttribute(c)):"attributes"===a.type&&"src"===c&&"IFRAME"===b.nodeName?i(b.contentDocument):"childList"===a.type&&(Array.from(a.addedNodes).forEach(function(a){"IFRAME"===a.nodeName?(a.contentDocument&&(n(a.contentDocument),h(a.contentDocument)),a.addEventListener("load",function(){n(this.contentDocument),h(this.contentDocument)})):h(a)}),Array.from(a.removedNodes).forEach(function(a){i("IFRAME"===a.nodeName?a.contentDocument:a)}))})}var c=new MutationObserver(b);c.observe(a,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,characterData:!1,characterDataOldValue:!1})}var o={},p={};Reflect.defineProperty(a.DataTier,"views",{value:{}}),Reflect.defineProperty(a.DataTier.views,"processChanges",{value:k}),Reflect.defineProperty(a.DataTier.views,"applyRule",{value:l}),n(document),h(document)}(this),function(a){"use strict";var b=a.DataTier.rules.add;b("tieValue",{dataToView:function(a,b){b.value=a?a:""}}),b("tieText",{dataToView:function(a,b){b.textContent=a?a.toString():""}}),b("tiePlaceholder",{dataToView:function(a,b){b.placeholder=a?a:""}}),b("tieTooltip",{dataToView:function(a,b){b.title=a?a:""}}),b("tieSrc",{dataToView:function(a,b){b.src=a?a:""}}),b("tieHRef",{dataToView:function(a,b){b.href=a?a:""}}),b("tieDateValue",{dataToView:function(a,b){b.value=a?a.toLocaleString():""}}),b("tieDateText",{dataToView:function(a,b){b.textContent=a?a.toLocaleString():""}}),b("tieClasses",{dataToView:function(a,b){var c=a&&Array.isArray(a)?a:[];Array.from(b.classList).forEach(function(a){b.classList.remove(a)}),c.length&&b.classList.add.apply(b.classList,c)}}),b("tieList",{parseParam:function(a){return this.constructor.prototype.parseParam(a.split(/\s*=>\s*/)[0])},dataToView:function(a,b){function c(a,b){for(var c=Array.from(l.querySelectorAll('[data-list-item-aid="'+b+'"]'));c.length>a;)l.removeChild(c.pop());return c.length}var d,e,f,g,h,i,j,k,l=b.parentNode;if("TEMPLATE"!==b.nodeName)throw new Error("tieList may be defined on template elements only");if(b.dataset.listSourceAid||(b.dataset.listSourceAid=(new Date).getTime()),d=c(a?a.length:0,b.dataset.listSourceAid),a&&d<a.length)if(f=b.dataset.tieList.trim().split(/\s+/),f&&3===f.length&&"=>"===f[1]){for(g=f[2],i=b.ownerDocument,j=i.createDocumentFragment();d<a.length;d++){for(e=i.importNode(b.content,!0),h=Array.prototype.slice.call(e.querySelectorAll("*"),0),h.forEach(function(a){Object.keys(a.dataset).forEach(function(b){0===a.dataset[b].indexOf(g)&&(a.dataset[b]=a.dataset[b].replace(g,f[0]+"."+d))})}),j.appendChild(e),k=j.lastChild;k.nodeType!==Node.ELEMENT_NODE&&null!==k.previousSibling;)k=k.previousSibling;k.dataset.listItemAid=b.dataset.listSourceAid}l.appendChild(j)}else console.error('invalid parameter for "tieList" rule specified')}})}(this); |
{ | ||
"name": "data-tier", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"main": "dist/data-tier.js", | ||
@@ -5,0 +5,0 @@ "files": [ |
100
README.md
@@ -17,9 +17,14 @@ [![npm version](https://badge.fury.io/js/data-tier.svg)](https://badge.fury.io/js/data-tier) | ||
- Support custom pre-processors for both data-to-view and view-to-data flows | ||
- Support custom pre-processors/interceptors for both data-to-view and view-to-data flows | ||
- Add rule to change any arbitrary attribute | ||
- Add rule for action (mouse? keyboard? any and provide the action with the event data?) | ||
- API reference | ||
- Possibility to override global rules on tie level | ||
- Change rule detection and appliance inner interface to broaden the possibilities of rules configurations | ||
#### Versions | ||
- __0.6.6__ | ||
- Added a possibility to create a tie without providing any initial data, for early setup with lazy data provisioning | ||
- __0.6.5__ | ||
@@ -74,2 +79,71 @@ - Fixed a case that element having no dataset breaks the views collection flow (this is not a valid case, but see this [issue](https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10790130/#) in Edge, so got to be defensive here) | ||
# Base concepts | ||
The library utilizes 2 main concepts __Ties__ and __Rules__. | ||
### Tie | ||
__Tie__ holds an observable data structure (object or array) associated with tie's name, it's about __what__ to tie. | ||
Thus, ties serve most and foremost data segregation and management purposes. | ||
Data within a tie is referenced by __path__: dot (`.`) separated keys along the object's hierarchy where in case of arrays index being the key. Consider the following data structure: | ||
```javascript | ||
let bands = [ | ||
{ | ||
id: 1234, | ||
name: 'Dream Theater', | ||
since: 1985, | ||
albums: [ | ||
{ id: 2345, name: 'When Dream and Day Unite', since: 1988 }, | ||
{ id: 2346, name: 'Images and Words', since: 1991 } | ||
] | ||
}, | ||
... | ||
]; | ||
``` | ||
Now one can create a tie named 'bandsTie' and set its data to be (an observable clone of) the bands array. | ||
Having that, any UI element would be tied to this dataset via the tie name and the path: | ||
- `bandsTie.0` - refer to the whole object at index 0 of our array | ||
- `bandsTie.length` - `length` property, inherited from the native `Array`, may also be used | ||
- `bandsTie.0.name` - path can get deeper... | ||
- `bandsTie.0.albums.1.since` - ...actually, it can get to any level of deepness | ||
Important: the first item in the path is always the tie's name. | ||
Basically, it is possible to create a single dataset for the whole application, making a single 'uber-tie' from it and operating all of the ties from there, but it should be considered as a bad practice from design correctness point of view. | ||
Having say that, I'll note, that there is no limitations on the size or the structure complexity of the tied model, nor there are any negative effects of those on application performance. | ||
Tie object not meant to hold the link between the data and its namespace only, but also tie's specific configurations and customizations. | ||
Currently in the backlog there are a such a features like supporting custom interceptors for both flows - data-to-view and view-to-data. | ||
Those features are under ongoing development and enhancements. For more details see [__API reference__](api-reference.md). | ||
### Rule | ||
__Rule__ is a definition of presentation logic, it's about __how__ to vizualize the data. | ||
Each rule has it's own unique name given to it upon registration. | ||
Rules are applied via the DOM's `data-*` attributes joining the `data-` prefix with rule's name: `data-tie-text` applies rule created with name 'tieRule'. | ||
Let's see the following example: | ||
```html | ||
<span data-tie-text="bandsTie.length" | ||
data-tie-tooltip="bandsTie.totalTooltip"> | ||
</span> | ||
... | ||
<div> | ||
<template data-tie-list="bandsTie.0.albums => album"> | ||
<span data-tie-text="album.name"></span> | ||
</template> | ||
</div> | ||
``` | ||
In the first part we tie between the `span` (view) and the model (we have tied it to both, `length` and `totalTooltip` values), while using 2 rules to say, how the value will be visualized. | ||
Attributes' values (`bandsTie.length`, `bandsTie.totalTooltip`) are rules' configurations for this specific instance and their syntax/content is part of each rule's API. | ||
In most cases the tie name and the path to the data would be sufficient, but conceptually rule's configuration may be anything rule needs. | ||
Thus, in the second part a `template` element tied by a 'tieList' rule. This rule expects more rich content in its configuration: tie name and path for sure, but also some name for an item within iteration (here - 'album', and see its usage in the inner span element). | ||
There is a set of rules bundled with the library, they are described in the [__Rules reference__](rules-reference.md). | ||
This set will eventually be updated and enhanced upon a needs and feedbacks from real world usages. | ||
But even more important is the fact, that rules may be created and added by a consuming application. | ||
This can be done at any phase of application's lifecycle, so there is no special ceremony around it whatsoever. | ||
Rules management described in the relevant section in [__API reference__](api-reference.md). | ||
# Basic example | ||
@@ -79,5 +153,5 @@ | ||
In order to let this happen, two actions need to be done: | ||
1. any model to be shown should be registered in the `DataTier` service | ||
2. DOM elements intended to visualize the model need to be decorated with an appropriate declaration | ||
In order to make this happen, two things need to be done: | ||
- any model to be shown should be registered in the `DataTier` service | ||
- DOM elements intended to visualize the model need to be decorated with an appropriate declaration | ||
@@ -88,3 +162,3 @@ The above two may happen in any order, in any phase in the application lifecycle. `DataTier` supports lazy binding, watching for DOM changes as well as for a data changes and will pick up any new linking information relevant and tie the things up. | ||
### Functional part | ||
### Code part | ||
```javascript | ||
@@ -105,11 +179,11 @@ var user = { | ||
### Declarative part | ||
### HTML part | ||
```html | ||
<div> | ||
<span data-tie-text="userInfo:name"></span> | ||
<span data-tie-text="userInfo:age"></span> | ||
<input type="checkbox" data-tie-value="userInfo:active"> | ||
<span data-tie-text="userInfo.name"></span> | ||
<span data-tie-text="userInfo.age"></span> | ||
<input type="checkbox" data-tie-value="userInfo.active"> | ||
<div> | ||
<input type="text" data-tie-value="userInfo:address.street"> | ||
<input type="text" data-tie-value="userInfo:address.apartment"> | ||
<input type="text" data-tie-value="userInfo.address.street"> | ||
<input type="text" data-tie-value="userInfo.address.apartment"> | ||
</div> | ||
@@ -120,2 +194,4 @@ </div> | ||
For a more thorough API documentation see [API Reference](api-reference.md) page. | ||
For an extended tutorial see [__this__](tutorial.md) page. | ||
For a more thorough API documentation see [__API Reference__](api-reference.md). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85200
1380
192