faster-dom
Advanced tools
@@ -278,2 +278,5 @@ // Thank you, very much https://github.com/krasimir/navigo | ||
get value() { | ||
return this.obs.value; | ||
} | ||
get observer() { | ||
return this.obs; | ||
@@ -336,3 +339,3 @@ } | ||
fdClassesNode = node.classList; | ||
const clsObs = node.classList.value; | ||
const clsObs = node.classList.observer; | ||
Object.keys(clsObs.value).forEach(key => { | ||
@@ -361,3 +364,3 @@ const value = clsObs.value[key]; | ||
fdPropsNode = node.props; | ||
const propsObs = node.props.value; | ||
const propsObs = node.props.observer; | ||
setProps(rootNode, propsObs.value); | ||
@@ -384,3 +387,3 @@ propsObs.addSubscriber(newProps => { | ||
fdStyleNode = node.styles; | ||
const styleObs = fdStyleNode.value; | ||
const styleObs = fdStyleNode.observer; | ||
setNodeStyle(rootNode, styleObs.value); | ||
@@ -398,3 +401,3 @@ styleObs.addSubscriber(newStyles => { | ||
fdAttrsNode = node.attrs; | ||
const attrsObs = node.attrs.value; | ||
const attrsObs = node.attrs.observer; | ||
setNodeAttrs(rootNode, attrsObs.value); | ||
@@ -401,0 +404,0 @@ attrsObs.addSubscriber(newAttrs => { |
@@ -297,2 +297,9 @@ // Thank you, very much https://github.com/krasimir/navigo | ||
get: function () { | ||
return this.obs.value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(fdObject.prototype, "observer", { | ||
get: function () { | ||
return this.obs; | ||
@@ -360,3 +367,3 @@ }, | ||
fdClassesNode = node.classList; | ||
var clsObs_1 = node.classList.value; | ||
var clsObs_1 = node.classList.observer; | ||
Object.keys(clsObs_1.value).forEach(function (key) { | ||
@@ -385,3 +392,3 @@ var value = clsObs_1.value[key]; | ||
fdPropsNode = node.props; | ||
var propsObs = node.props.value; | ||
var propsObs = node.props.observer; | ||
setProps(rootNode, propsObs.value); | ||
@@ -408,3 +415,3 @@ propsObs.addSubscriber(function (newProps) { | ||
fdStyleNode = node.styles; | ||
var styleObs = fdStyleNode.value; | ||
var styleObs = fdStyleNode.observer; | ||
setNodeStyle(rootNode, styleObs.value); | ||
@@ -422,3 +429,3 @@ styleObs.addSubscriber(function (newStyles) { | ||
fdAttrsNode = node.attrs; | ||
var attrsObs = node.attrs.value; | ||
var attrsObs = node.attrs.observer; | ||
setNodeAttrs(rootNode, attrsObs.value); | ||
@@ -425,0 +432,0 @@ attrsObs.addSubscriber(function (newAttrs) { |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self)["faster-dom"]={})}(this,function(t){"use strict";var e=/([:*])(\w+)/g,n=/\*/g,r="([^/]+)",o="(?:.*)",i="(?:/$|$)",s="",a=!("undefined"==typeof window||!window.history||!window.history.pushState),c=window.requestIdleCallback||requestAnimationFrame||setTimeout;function u(t,e){"string"!=typeof e?requestAnimationFrame(function(){Object.keys(e).forEach(function(n){t.style.setProperty(n,e[n])})}):requestAnimationFrame(function(){t.style.cssText=e})}function f(t,e){Object.keys(e).forEach(function(n){e[n]||""===e[n]?t.setAttribute(n,e[n]):t.removeAttribute(n)})}function l(t,e){Object.keys(e).forEach(function(n){t[n]=e[n]})}function p(t,e){t&&e&&Object.keys(e).forEach(function(n){Array.isArray(e[n])?e[n].forEach(function(e){t.addEventListener(n,e)}):t.addEventListener(n,e[n])})}function d(t,e){t&&e&&Object.keys(e).forEach(function(n){Array.isArray(e[n])?e[n].forEach(function(e){t.removeEventListener(n,e)}):t.removeEventListener(n,e[n])})}function h(t){if(t)for(;t.firstChild;)t.removeChild(t.firstChild)}function v(t,e,n){for(var r,o,i=[],s=3;s<arguments.length;s++)i[s-3]=arguments[s];if(t){if(n)return t.children&&t.children.forEach(function(t){v.apply(void 0,[t,e,n].concat(i))}),void(t.instance&&(r=t.instance)[e].apply(r,i));t.instance&&(o=t.instance)[e].apply(o,i),t.children&&t.children.forEach(function(t){v.apply(void 0,[t,e,n].concat(i))})}}function y(t){return t instanceof RegExp?t:t.replace(/\/+$/,"").replace(/^\/+/,"^/")}function b(t,a){return void 0===a&&(a=[]),a.map(function(a){var c=function(t){var a,c=[];a=t instanceof RegExp?t:new RegExp(t.replace(e,function(t,e,n){return c.push(n),r}).replace(n,o)+i,s);return{regexp:a,paramNames:c}}(y(a.path)),u=c.regexp,f=c.paramNames,l=t.match(u),p=function(t,e){return 0===e.length?null:t?t.slice(1,t.length).reduce(function(t,n,r){return null===t&&(t={}),t[e[r]]=decodeURIComponent(n),t},null):null}(l,f);return!!l&&{match:l,route:a,params:p}}).filter(function(t){return t})}function m(t,e){return void 0===e&&(e=[]),b(function(t,e,n){void 0===e&&(e=!1),void 0===n&&(n="#");var r,o=function(t){return t.split(/\?(.*)?$/)[0]};return void 0===n&&(n="#"),a&&!e?o(t).split(n)[0]:(r=t.split(n)).length>1?o(r[1]):o(r[0])}(t),e)[0]||!1}function g(t,e){if(0!==e.length){var n=document.createDocumentFragment();e.forEach(function(t){Array.isArray(t)?g(n,t):n.appendChild(t)}),t.appendChild(n)}}var E=function(){function t(t,e){void 0===e&&(e=!1),this._value=t,this.forces=e,this.subscribers=[],this.isDestroy=!1,this.firstState=t}return Object.defineProperty(t.prototype,"value",{get:function(){return this._value},set:function(t){this.isDestroy||(this._value!==t||this.forces)&&(this._value=t,this.subscribers.length&&this.subscribers.forEach(function(e){e(t)}))},enumerable:!0,configurable:!0}),t.prototype.destroy=function(t){void 0===t&&(t=!1),this.isDestroy||(t&&(this.subscribers=[]),this.isDestroy=!0)},t.prototype.reInit=function(){this.isDestroy=!1,this.value=this.firstState},t.prototype.addSubscriber=function(t){this.isDestroy||this.subscribers.push(t)},t.prototype.removeSubscriber=function(t){var e=this.subscribers.indexOf(t);e>-1&&this.subscribers.splice(e,1)},t}(),_=function(){function t(t){void 0===t&&(t={});var e=this;this.obsArr=[],this.values={},this.obs=new E(this.values,!0),this.isDestroyed=!1,Object.keys(t).forEach(function(n){var r=t[n];"object"==typeof r?(e.obsArr.push(r),e.values[n]=r.value,r.addSubscriber(function(t){e.values[n]=t,e.obs.value=e.values})):e.values[n]=r})}return Object.defineProperty(t.prototype,"value",{get:function(){return this.obs},enumerable:!0,configurable:!0}),t.prototype.reInit=function(){this.isDestroyed=!1,this.obs.reInit(),this.obsArr.forEach(function(t){t.reInit()})},t.prototype.destroy=function(t){void 0===t&&(t=!1),this.isDestroyed||(this.obs.destroy(t),this.obsArr.forEach(function(e){e.destroy(t)}),this.isDestroyed=!0)},t}(),w="instance";function O(t){if(!1===t.show)return null;var e,n,r,o,i="textNode"!==t.tag?document.createElement(t.tag):document.createTextNode("");if(t.domNode=i,null!==t.textValue||void 0!==t.textValue)if("object"==typeof t.textValue){var s=t.textValue;s.addSubscriber(function(t){i.textContent=t}),i.textContent=s.value}else i.textContent=t.textValue;if("textNode"!==t.tag){if(t.classList)if("string"==typeof t.classList)i.className=t.classList;else if(Array.isArray(t.classList))t.classList.forEach(function(t){i.classList.add(t)});else{e=t.classList;var a=t.classList.value;Object.keys(a.value).forEach(function(t){return a.value[t]?i.classList.add(t):i.classList.remove(t)}),a.addSubscriber(function(t){Object.keys(t).forEach(function(e){return t[e]?i.classList.add(e):i.classList.remove(e)})})}if(t.props)if(t.props instanceof _){r=t.props;var c=t.props.value;l(i,c.value),c.addSubscriber(function(t){l(i,t)})}else l(i,t.props);if(t.styles)if(t.styles instanceof _){var h=(o=t.styles).value;u(i,h.value),h.addSubscriber(function(t){u(i,t)})}else t.styles instanceof E?(o=t.styles,u(i,o.value),o.addSubscriber(function(t){u(i,t)})):u(i,t.styles);if(t.attrs)if(t.attrs instanceof _){n=t.attrs;var y=t.attrs.value;f(i,y.value),y.addSubscriber(function(t){f(i,t)})}else f(i,t.attrs);if(t.children){var b=[];t.children.forEach(function(t){if(t){if(Array.isArray(t)){var e=[];return t.forEach(function(t){if(t.tag){var n=O(Object.assign(t,{parent:i}));n&&e.push(n)}else e.push(t)}),t._parent=i,void b.push(e)}if(t.tag){var n=O(Object.assign(t,{parent:i}));n&&b.push(n)}else b.push(t)}}),g(i,b)}t.listeners&&p(i,t.listeners)}t.instance&&(i[w]=t.instance);var m=function(){"textNode"!==t.tag&&d(i,t.listeners),n&&n.destroy(),r&&r.destroy(),e&&e.destroy(),o&&e.destroy(),v(t,"destroy",!0)};if("object"==typeof t.show){var j=document.createComment("");return t.show.addSubscriber(function(s){var a=t.parent?t.parent:null;s?a&&(j.parentNode===a&&a.replaceChild(i,j),v(t,"reInit",!1),o&&e.reInit(),e&&e.reInit(),r&&r.reInit(),n&&n.reInit(),"textNode"!==t.tag&&p(i,t.listeners)):a&&(m(),i.parentNode===a&&a.replaceChild(j,i))}),t.show.value?(t.instance&&t.instance.onInit(),i):(m(),j)}return t.instance&&t.instance.onInit(),i}var j=function(){function t(){this.reactive={},this.fdObjects={},this.fdStyles={}}return t.prototype.onDestroy=function(){},t.prototype.onInit=function(){},t.prototype.reInit=function(){var t=this;Object.keys(this.fdStyles).forEach(function(e){t.fdStyles[e].reInit()}),Object.keys(this.fdObjects).forEach(function(e){t.fdObjects[e].reInit()}),Object.keys(this.reactive).forEach(function(e){t.reactive[e].reInit()}),this.onInit()},t.prototype.destroy=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];!0===e[0]&&function t(e){e.listeners&&d(e.domNode,e.listeners),e.children&&e.children.forEach(function(e){!e.instance&&e.tag&&t(e)})}(this.template),Object.keys(this.fdObjects).forEach(function(n){var r;(r=t.fdObjects[n]).destroy.apply(r,e)}),Object.keys(this.reactive).forEach(function(n){var r;(r=t.reactive[n]).destroy.apply(r,e)}),Object.keys(this.fdStyles).forEach(function(n){var r;(r=t.fdStyles[n]).destroy.apply(r,e)}),this.onDestroy()},t}(),S=function(t,e){return(S=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};var C=function(){return(C=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function x(t,e){return void 0===e&&(e=!1),new E(t,e)}function A(t,e,n,r,o){void 0===n&&(n=[]);var i,s,a,c,u=!1;return o?(s=o,i=t):(c=typeof(a=t),i=(u=null===a||"object"!==c&&"function"!==c)?{id:r,value:t}:t,s=function(){return i}),"function"==typeof e?C({},e.apply(void 0,n.map(function(e){return"function"==typeof e?e(u?i.value:t):e}).concat([r])),{fdKey:s(i)}):C({},e,{textValue:e.textValue(u?i.value:t),fdKey:s(i)})}function I(t){return t.replace(/\/$/,"").split("/").length}function N(t,e){return I(e.path)-I(t.path)}var L=new(function(t){function e(e){var n=t.call(this)||this;return n.baseHref=e,n._arrPaths=[],n._cUrl=x(""),n._cState=x(""),n._currentComp=null,n.template={tag:"div",classList:["router-view"]},n.onPopState=function(t){n.applyUrl((t.isTrusted?t.state:n.baseHref+t.state).replace(/[\\\\\/]+/g,"/"))},n.applyUrl=function(t){var e=m(t,n._arrPaths);if(e){var r=e.route;if(n._currentComp&&v(n._currentComp,"destroy",!0,!0),n._cState.value=r.path,n._cUrl.value=t,h(n.template.domNode),r.resolver)r.resolver(e.params).then(function(e){n.createComponent(t,r,e)});else n.createComponent(t,r)}},window.addEventListener("popstate",n.onPopState),n}return function(t,e){function n(){this.constructor=t}S(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e.prototype.setPaths=function(t){var e=this;void 0===t&&(t={}),Object.keys(t).forEach(function(n){e._arrPaths.push({component:t[n].component,title:t[n].title,path:y((e.baseHref+n).replace(/[\\\\\/]+/g,"/")),resolver:t[n].resolver})}),this._arrPaths.sort(N),this.initRouter()},e.prototype.initRouter=function(){this.applyUrl(window.location.pathname.replace(/[\\\\\/]+/g,"/"))},e.prototype.createComponent=function(t,e,n){var r=this;e.title&&("function"==typeof e.title?document.title=e.title(n):document.title=e.title),window.history.pushState(this._cUrl.value,document.title,this._cUrl.value);var o=e.component(n);this._currentComp=o,Promise.resolve().then(function(){r.template.domNode.appendChild(O(o))})},e.prototype.onDestroy=function(){window.removeEventListener("popstate",this.onPopState)},e.prototype.goToUrl=function(t){this._cUrl.value!==(this.baseHref+t).replace(/[\\\\\/]+/g,"/")&&dispatchEvent(new PopStateEvent("popstate",{state:t}))},e.prototype.isCurrentRoute=function(t){var e=m((this.baseHref+t).replace(/[\\\\\/]+/g,"/"),[{path:this._cState.value}]);return!!e&&""!==e.match[0]},e.prototype.getCurrentRoute=function(){return this._cUrl},e.prototype.getCurrentState=function(){return this._cState},e}(j))(window.location.pathname);t.Component=j,t.Composite=function(t,e){if(0!==t.length){var n=function(t){return e.apply(void 0,t.map(function(t){return t.value}))},r=n(t),o=new E(r);return t.forEach(function(e){e.addSubscriber(function(){o.value=n(t)})}),o}},t.Observer=E,t.Router=L,t.bootstrap=function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=document.querySelector(t);if(!o)throw Error('FastDOM Bootstrap Error: No container found for selector "'+t+'"');o.appendChild(O(e.call.apply(e,[e].concat(n))))},t.createComponent=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=new(t.bind.apply(t,[void 0].concat(e)));return r.template.instance=r,r.template},t.createRouter=function(t){return L.setPaths(t),L.template},t.fdFor=function(t,e,n,r){if(void 0===n&&(n=[]),Array.isArray(t))return t.map(function(t,o){return A(t,e,n,o,r)});var o=new Map,i=t.value.map(function(t,i){var s=A(t,e,n,i,r);return o.set(s.fdKey,i),s});return t.addSubscriber(function(t){var s=i._parent,a=i.length;if(0===t.length){if(a){h(s);var u=i.slice();c(function(){u.forEach(function(t){v(t,"destroy",!0,!0)})})}return i=t,o.clear(),void(i._parent=s)}if(0===a){i=t.map(function(t,i){var s=A(t,e,n,i,r);return o.set(s.fdKey,i),s});var f=[];return i.forEach(function(t){f.push(O(t))}),g(s,f),void(i._parent=s)}for(var l=[],p=t.map(function(t,o){return A(t,e,n,o,r)}),d=[],y=0;y<a;y++)d.push(!1);var b=p.map(function(t){var e=o.get(t.fdKey);return void 0!==e?[t,e]:[t,-1]});b.forEach(function(t){var e=t[1];e>-1&&(d[e]=!0)}),d.forEach(function(t,e){t||(s.removeChild(i[e].domNode),l.push(i[e]))}),c(function(){l.forEach(function(t){v(t,"destroy",!0,!0)})});var m=0,E=[];b.forEach(function(t,e){var n=t[0],r=t[1];if(-1===r)return E.push(O(n)),void(m+=1);i[r].domNode!==s.children[e+m]&&(s.insertBefore(i[r].domNode,s.children[e+m]),m+=1)}),g(s,E),o.clear(),p.forEach(function(t,e){t.domNode=s.children[e],o.set(t.fdKey,e)}),(i=p)._parent=s}),i},t.fdIf=function(t){return x(t)},t.fdObject=_,t.fdValue=x,t.generateNode=O,t.matchRoute=m,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self)["faster-dom"]={})}(this,function(t){"use strict";var e=/([:*])(\w+)/g,n=/\*/g,r="([^/]+)",o="(?:.*)",i="(?:/$|$)",s="",a=!("undefined"==typeof window||!window.history||!window.history.pushState),c=window.requestIdleCallback||requestAnimationFrame||setTimeout;function u(t,e){"string"!=typeof e?requestAnimationFrame(function(){Object.keys(e).forEach(function(n){t.style.setProperty(n,e[n])})}):requestAnimationFrame(function(){t.style.cssText=e})}function f(t,e){Object.keys(e).forEach(function(n){e[n]||""===e[n]?t.setAttribute(n,e[n]):t.removeAttribute(n)})}function l(t,e){Object.keys(e).forEach(function(n){t[n]=e[n]})}function p(t,e){t&&e&&Object.keys(e).forEach(function(n){Array.isArray(e[n])?e[n].forEach(function(e){t.addEventListener(n,e)}):t.addEventListener(n,e[n])})}function d(t,e){t&&e&&Object.keys(e).forEach(function(n){Array.isArray(e[n])?e[n].forEach(function(e){t.removeEventListener(n,e)}):t.removeEventListener(n,e[n])})}function h(t){if(t)for(;t.firstChild;)t.removeChild(t.firstChild)}function v(t,e,n){for(var r,o,i=[],s=3;s<arguments.length;s++)i[s-3]=arguments[s];if(t){if(n)return t.children&&t.children.forEach(function(t){v.apply(void 0,[t,e,n].concat(i))}),void(t.instance&&(r=t.instance)[e].apply(r,i));t.instance&&(o=t.instance)[e].apply(o,i),t.children&&t.children.forEach(function(t){v.apply(void 0,[t,e,n].concat(i))})}}function y(t){return t instanceof RegExp?t:t.replace(/\/+$/,"").replace(/^\/+/,"^/")}function b(t,a){return void 0===a&&(a=[]),a.map(function(a){var c=function(t){var a,c=[];a=t instanceof RegExp?t:new RegExp(t.replace(e,function(t,e,n){return c.push(n),r}).replace(n,o)+i,s);return{regexp:a,paramNames:c}}(y(a.path)),u=c.regexp,f=c.paramNames,l=t.match(u),p=function(t,e){return 0===e.length?null:t?t.slice(1,t.length).reduce(function(t,n,r){return null===t&&(t={}),t[e[r]]=decodeURIComponent(n),t},null):null}(l,f);return!!l&&{match:l,route:a,params:p}}).filter(function(t){return t})}function m(t,e){return void 0===e&&(e=[]),b(function(t,e,n){void 0===e&&(e=!1),void 0===n&&(n="#");var r,o=function(t){return t.split(/\?(.*)?$/)[0]};return void 0===n&&(n="#"),a&&!e?o(t).split(n)[0]:(r=t.split(n)).length>1?o(r[1]):o(r[0])}(t),e)[0]||!1}function g(t,e){if(0!==e.length){var n=document.createDocumentFragment();e.forEach(function(t){Array.isArray(t)?g(n,t):n.appendChild(t)}),t.appendChild(n)}}var E=function(){function t(t,e){void 0===e&&(e=!1),this._value=t,this.forces=e,this.subscribers=[],this.isDestroy=!1,this.firstState=t}return Object.defineProperty(t.prototype,"value",{get:function(){return this._value},set:function(t){this.isDestroy||(this._value!==t||this.forces)&&(this._value=t,this.subscribers.length&&this.subscribers.forEach(function(e){e(t)}))},enumerable:!0,configurable:!0}),t.prototype.destroy=function(t){void 0===t&&(t=!1),this.isDestroy||(t&&(this.subscribers=[]),this.isDestroy=!0)},t.prototype.reInit=function(){this.isDestroy=!1,this.value=this.firstState},t.prototype.addSubscriber=function(t){this.isDestroy||this.subscribers.push(t)},t.prototype.removeSubscriber=function(t){var e=this.subscribers.indexOf(t);e>-1&&this.subscribers.splice(e,1)},t}(),O=function(){function t(t){void 0===t&&(t={});var e=this;this.obsArr=[],this.values={},this.obs=new E(this.values,!0),this.isDestroyed=!1,Object.keys(t).forEach(function(n){var r=t[n];"object"==typeof r?(e.obsArr.push(r),e.values[n]=r.value,r.addSubscriber(function(t){e.values[n]=t,e.obs.value=e.values})):e.values[n]=r})}return Object.defineProperty(t.prototype,"value",{get:function(){return this.obs.value},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"observer",{get:function(){return this.obs},enumerable:!0,configurable:!0}),t.prototype.reInit=function(){this.isDestroyed=!1,this.obs.reInit(),this.obsArr.forEach(function(t){t.reInit()})},t.prototype.destroy=function(t){void 0===t&&(t=!1),this.isDestroyed||(this.obs.destroy(t),this.obsArr.forEach(function(e){e.destroy(t)}),this.isDestroyed=!0)},t}(),_="instance";function j(t){if(!1===t.show)return null;var e,n,r,o,i="textNode"!==t.tag?document.createElement(t.tag):document.createTextNode("");if(t.domNode=i,null!==t.textValue||void 0!==t.textValue)if("object"==typeof t.textValue){var s=t.textValue;s.addSubscriber(function(t){i.textContent=t}),i.textContent=s.value}else i.textContent=t.textValue;if("textNode"!==t.tag){if(t.classList)if("string"==typeof t.classList)i.className=t.classList;else if(Array.isArray(t.classList))t.classList.forEach(function(t){i.classList.add(t)});else{e=t.classList;var a=t.classList.observer;Object.keys(a.value).forEach(function(t){return a.value[t]?i.classList.add(t):i.classList.remove(t)}),a.addSubscriber(function(t){Object.keys(t).forEach(function(e){return t[e]?i.classList.add(e):i.classList.remove(e)})})}if(t.props)if(t.props instanceof O){r=t.props;var c=t.props.observer;l(i,c.value),c.addSubscriber(function(t){l(i,t)})}else l(i,t.props);if(t.styles)if(t.styles instanceof O){var h=(o=t.styles).observer;u(i,h.value),h.addSubscriber(function(t){u(i,t)})}else t.styles instanceof E?(o=t.styles,u(i,o.value),o.addSubscriber(function(t){u(i,t)})):u(i,t.styles);if(t.attrs)if(t.attrs instanceof O){n=t.attrs;var y=t.attrs.observer;f(i,y.value),y.addSubscriber(function(t){f(i,t)})}else f(i,t.attrs);if(t.children){var b=[];t.children.forEach(function(t){if(t){if(Array.isArray(t)){var e=[];return t.forEach(function(t){if(t.tag){var n=j(Object.assign(t,{parent:i}));n&&e.push(n)}else e.push(t)}),t._parent=i,void b.push(e)}if(t.tag){var n=j(Object.assign(t,{parent:i}));n&&b.push(n)}else b.push(t)}}),g(i,b)}t.listeners&&p(i,t.listeners)}t.instance&&(i[_]=t.instance);var m=function(){"textNode"!==t.tag&&d(i,t.listeners),n&&n.destroy(),r&&r.destroy(),e&&e.destroy(),o&&e.destroy(),v(t,"destroy",!0)};if("object"==typeof t.show){var w=document.createComment("");return t.show.addSubscriber(function(s){var a=t.parent?t.parent:null;s?a&&(w.parentNode===a&&a.replaceChild(i,w),v(t,"reInit",!1),o&&e.reInit(),e&&e.reInit(),r&&r.reInit(),n&&n.reInit(),"textNode"!==t.tag&&p(i,t.listeners)):a&&(m(),i.parentNode===a&&a.replaceChild(w,i))}),t.show.value?(t.instance&&t.instance.onInit(),i):(m(),w)}return t.instance&&t.instance.onInit(),i}var w=function(){function t(){this.reactive={},this.fdObjects={},this.fdStyles={}}return t.prototype.onDestroy=function(){},t.prototype.onInit=function(){},t.prototype.reInit=function(){var t=this;Object.keys(this.fdStyles).forEach(function(e){t.fdStyles[e].reInit()}),Object.keys(this.fdObjects).forEach(function(e){t.fdObjects[e].reInit()}),Object.keys(this.reactive).forEach(function(e){t.reactive[e].reInit()}),this.onInit()},t.prototype.destroy=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];!0===e[0]&&function t(e){e.listeners&&d(e.domNode,e.listeners),e.children&&e.children.forEach(function(e){!e.instance&&e.tag&&t(e)})}(this.template),Object.keys(this.fdObjects).forEach(function(n){var r;(r=t.fdObjects[n]).destroy.apply(r,e)}),Object.keys(this.reactive).forEach(function(n){var r;(r=t.reactive[n]).destroy.apply(r,e)}),Object.keys(this.fdStyles).forEach(function(n){var r;(r=t.fdStyles[n]).destroy.apply(r,e)}),this.onDestroy()},t}(),S=function(t,e){return(S=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};var C=function(){return(C=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function x(t,e){return void 0===e&&(e=!1),new E(t,e)}function A(t,e,n,r,o){void 0===n&&(n=[]);var i,s,a,c,u=!1;return o?(s=o,i=t):(c=typeof(a=t),i=(u=null===a||"object"!==c&&"function"!==c)?{id:r,value:t}:t,s=function(){return i}),"function"==typeof e?C({},e.apply(void 0,n.map(function(e){return"function"==typeof e?e(u?i.value:t):e}).concat([r])),{fdKey:s(i)}):C({},e,{textValue:e.textValue(u?i.value:t),fdKey:s(i)})}function I(t){return t.replace(/\/$/,"").split("/").length}function N(t,e){return I(e.path)-I(t.path)}var L=new(function(t){function e(e){var n=t.call(this)||this;return n.baseHref=e,n._arrPaths=[],n._cUrl=x(""),n._cState=x(""),n._currentComp=null,n.template={tag:"div",classList:["router-view"]},n.onPopState=function(t){n.applyUrl((t.isTrusted?t.state:n.baseHref+t.state).replace(/[\\\\\/]+/g,"/"))},n.applyUrl=function(t){var e=m(t,n._arrPaths);if(e){var r=e.route;if(n._currentComp&&v(n._currentComp,"destroy",!0,!0),n._cState.value=r.path,n._cUrl.value=t,h(n.template.domNode),r.resolver)r.resolver(e.params).then(function(e){n.createComponent(t,r,e)});else n.createComponent(t,r)}},window.addEventListener("popstate",n.onPopState),n}return function(t,e){function n(){this.constructor=t}S(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e.prototype.setPaths=function(t){var e=this;void 0===t&&(t={}),Object.keys(t).forEach(function(n){e._arrPaths.push({component:t[n].component,title:t[n].title,path:y((e.baseHref+n).replace(/[\\\\\/]+/g,"/")),resolver:t[n].resolver})}),this._arrPaths.sort(N),this.initRouter()},e.prototype.initRouter=function(){this.applyUrl(window.location.pathname.replace(/[\\\\\/]+/g,"/"))},e.prototype.createComponent=function(t,e,n){var r=this;e.title&&("function"==typeof e.title?document.title=e.title(n):document.title=e.title),window.history.pushState(this._cUrl.value,document.title,this._cUrl.value);var o=e.component(n);this._currentComp=o,Promise.resolve().then(function(){r.template.domNode.appendChild(j(o))})},e.prototype.onDestroy=function(){window.removeEventListener("popstate",this.onPopState)},e.prototype.goToUrl=function(t){this._cUrl.value!==(this.baseHref+t).replace(/[\\\\\/]+/g,"/")&&dispatchEvent(new PopStateEvent("popstate",{state:t}))},e.prototype.isCurrentRoute=function(t){var e=m((this.baseHref+t).replace(/[\\\\\/]+/g,"/"),[{path:this._cState.value}]);return!!e&&""!==e.match[0]},e.prototype.getCurrentRoute=function(){return this._cUrl},e.prototype.getCurrentState=function(){return this._cState},e}(w))(window.location.pathname);t.Component=w,t.Composite=function(t,e){if(0!==t.length){var n=function(t){return e.apply(void 0,t.map(function(t){return t.value}))},r=n(t),o=new E(r);return t.forEach(function(e){e.addSubscriber(function(){o.value=n(t)})}),o}},t.Observer=E,t.Router=L,t.bootstrap=function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=document.querySelector(t);if(!o)throw Error('FastDOM Bootstrap Error: No container found for selector "'+t+'"');o.appendChild(j(e.call.apply(e,[e].concat(n))))},t.createComponent=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=new(t.bind.apply(t,[void 0].concat(e)));return r.template.instance=r,r.template},t.createRouter=function(t){return L.setPaths(t),L.template},t.fdFor=function(t,e,n,r){if(void 0===n&&(n=[]),Array.isArray(t))return t.map(function(t,o){return A(t,e,n,o,r)});var o=new Map,i=t.value.map(function(t,i){var s=A(t,e,n,i,r);return o.set(s.fdKey,i),s});return t.addSubscriber(function(t){var s=i._parent,a=i.length;if(0===t.length){if(a){h(s);var u=i.slice();c(function(){u.forEach(function(t){v(t,"destroy",!0,!0)})})}return i=t,o.clear(),void(i._parent=s)}if(0===a){i=t.map(function(t,i){var s=A(t,e,n,i,r);return o.set(s.fdKey,i),s});var f=[];return i.forEach(function(t){f.push(j(t))}),g(s,f),void(i._parent=s)}for(var l=[],p=t.map(function(t,o){return A(t,e,n,o,r)}),d=[],y=0;y<a;y++)d.push(!1);var b=p.map(function(t){var e=o.get(t.fdKey);return void 0!==e?[t,e]:[t,-1]});b.forEach(function(t){var e=t[1];e>-1&&(d[e]=!0)}),d.forEach(function(t,e){t||(s.removeChild(i[e].domNode),l.push(i[e]))}),c(function(){l.forEach(function(t){v(t,"destroy",!0,!0)})});var m=0,E=[];b.forEach(function(t,e){var n=t[0],r=t[1];if(-1===r)return E.push(j(n)),void(m+=1);i[r].domNode!==s.children[e+m]&&(s.insertBefore(i[r].domNode,s.children[e+m]),m+=1)}),g(s,E),o.clear(),p.forEach(function(t,e){t.domNode=s.children[e],o.set(t.fdKey,e)}),(i=p)._parent=s}),i},t.fdIf=function(t){return x(t)},t.fdObject=O,t.fdValue=x,t.generateNode=j,t.matchRoute=m,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -14,4 +14,7 @@ import { Observer } from './observer'; | ||
}); | ||
readonly value: Observer<{ | ||
readonly value: { | ||
[key: string]: T; | ||
}; | ||
readonly observer: Observer<{ | ||
[key: string]: T; | ||
}>; | ||
@@ -18,0 +21,0 @@ reInit(): void; |
{ | ||
"name": "faster-dom", | ||
"version": "0.0.44-alpha", | ||
"version": "0.0.45-alpha", | ||
"main": "faster-dom.umd.js", | ||
@@ -5,0 +5,0 @@ "module": "faster-dom.es5.js", |
@@ -11,3 +11,3 @@ # Faster Dom  [](https://circleci.com/gh/PxyUp/FastDom/tree/master) | ||
```sh | ||
yarn add faster-dom@0.0.44-alpha | ||
yarn add faster-dom@0.0.45-alpha | ||
``` | ||
@@ -14,0 +14,0 @@ |
89178
0.54%2049
0.69%