Comparing version 1.6.7 to 1.6.8
12
extra.js
@@ -100,4 +100,14 @@ 'use strict'; | ||
var isObservable = function isObservable(x) { | ||
return x && typeof x.subscribe === 'function'; | ||
}; | ||
var toObservable = function toObservable(x) { | ||
return isObservable(x) ? x : rxjs.of(x); | ||
}; | ||
var all = function all(obs) { | ||
return obs.length ? rxjs.combineLatest.apply(undefined, toConsumableArray(obs).concat([function () { | ||
return obs.length ? rxjs.combineLatest.apply(undefined, toConsumableArray(obs.map(toObservable)).concat([function () { | ||
for (var _len = arguments.length, xs = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -104,0 +114,0 @@ xs[_key] = arguments[_key]; |
@@ -237,3 +237,3 @@ 'use strict'; | ||
var all = function all(obs) { | ||
return obs.length ? rxjs.combineLatest.apply(undefined, toConsumableArray(obs).concat([function () { | ||
return obs.length ? rxjs.combineLatest.apply(undefined, toConsumableArray(obs.map(toObservable)).concat([function () { | ||
for (var _len = arguments.length, xs = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -389,3 +389,3 @@ xs[_key] = arguments[_key]; | ||
key: 'createElement', | ||
value: function createElement(isSvg, patch) { | ||
value: function createElement(isSvg, patch, context) { | ||
var node = (isSvg = isSvg || this.name === 'svg') ? document.createElementNS('http://www.w3.org/2000/svg', this.name) : document.createElement(this.name); | ||
@@ -395,3 +395,3 @@ | ||
this.updateAttrs(node, {}); | ||
this.updateChildren(node, [], isSvg, patch); | ||
this.updateChildren(node, [], isSvg, patch, context); | ||
@@ -402,10 +402,10 @@ return node; | ||
key: 'updateElement', | ||
value: function updateElement(node, previousTree, isSvg, patch) { | ||
value: function updateElement(node, previousTree, isSvg, patch, context) { | ||
if (previousTree.name !== this.name) { | ||
previousTree.removeElement(node); | ||
return this.createElement(isSvg, patch); | ||
return this.createElement(isSvg, patch, context); | ||
} else { | ||
this.updateEvents(node, previousTree.events); | ||
this.updateAttrs(node, previousTree.attrs); | ||
this.updateChildren(node, previousTree.children, isSvg, patch); | ||
this.updateChildren(node, previousTree.children, isSvg, patch, context); | ||
@@ -537,3 +537,3 @@ this.lifecycle.update(node); | ||
key: 'updateChildren', | ||
value: function updateChildren(node, previousChildren, isSvg, patch) { | ||
value: function updateChildren(node, previousChildren, isSvg, patch, context) { | ||
for (var index in this.children) { | ||
@@ -545,7 +545,7 @@ var childTree = this.children[index]; | ||
if (!previousChildNode) { | ||
var childNode = childTree.createElement(isSvg, patch); | ||
var childNode = childTree.createElement(isSvg, patch, context); | ||
node.appendChild(childNode); | ||
childTree.mount(childNode); | ||
} else { | ||
patch(previousChildNode, previousChildTree, childTree, isSvg); | ||
patch(previousChildNode, previousChildTree, childTree, isSvg, context); | ||
} | ||
@@ -614,6 +614,7 @@ } | ||
var isSvg = arguments[3]; | ||
var context = arguments[4]; | ||
if (vTree.constructor !== previousTree.constructor || vTree.key !== previousTree.key) { | ||
previousTree.removeElement(node); | ||
var newNode = vTree.createElement(isSvg, patch); | ||
var newNode = vTree.createElement(isSvg, patch, context); | ||
node.parentNode.replaceChild(newNode, node); | ||
@@ -623,3 +624,3 @@ vTree.mount(newNode); | ||
} else { | ||
var _newNode = vTree.updateElement(node, previousTree, isSvg, patch); | ||
var _newNode = vTree.updateElement(node, previousTree, isSvg, patch, context); | ||
if (_newNode) { | ||
@@ -699,3 +700,3 @@ node.parentNode.replaceChild(_newNode, node); | ||
key: 'createElement', | ||
value: function createElement(isSvg, patch) { | ||
value: function createElement(isSvg, patch, context) { | ||
var _this = this; | ||
@@ -709,7 +710,9 @@ | ||
var vdomStream = this.name(this.state.props.stream); | ||
var component = this.name(this.state.props.stream); | ||
if (!vdomStream) throw new Error('Component ' + this.name.name + ' must return a stream!'); | ||
if (!component) throw new Error('Component ' + this.name.name + ' must return a stream!'); | ||
this.state.subscription = vdomStream.pipe(flatten, operators.sample(sharedRaf)).subscribe({ | ||
var stream = typeof component === 'function' ? component(context) : component; | ||
this.state.subscription = stream.pipe(flatten, operators.sample(sharedRaf)).subscribe({ | ||
next: function next(newChildTree) { | ||
@@ -732,3 +735,3 @@ if (newChildTree instanceof VPatch) { | ||
key: 'updateElement', | ||
value: function updateElement(node, previousComponent, isSvg, patch) { | ||
value: function updateElement(node, previousComponent, isSvg, patch, context) { | ||
this.state = previousComponent.state; | ||
@@ -738,3 +741,3 @@ | ||
previousComponent.removeElement(node); | ||
return this.createElement(isSvg, patch); | ||
return this.createElement(isSvg, patch, context); | ||
} else { | ||
@@ -904,3 +907,3 @@ this.state.props.next(this.untouchedAttributes); | ||
// render :: Observable VirtualDOM -> DOMElement -> Promise Error () | ||
var render = function render(component, element) { | ||
var render = function render(component, element, context) { | ||
var rootNode = element.firstChild; | ||
@@ -915,6 +918,6 @@ var previousTree = void 0; | ||
if (!rootNode) { | ||
rootNode = vTree.createElement(false, patch); | ||
rootNode = vTree.createElement(false, patch, context); | ||
element.appendChild(rootNode); | ||
} else { | ||
patch(rootNode, previousTree, vTree); | ||
patch(rootNode, previousTree, vTree, false, context); | ||
} | ||
@@ -921,0 +924,0 @@ previousTree = vTree; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var createTag=_interopDefault(require("vdom-tag")),rxjs=require("rxjs"),operators=require("rxjs/operators"),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},slicedToArray=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),toArray=function(e){return Array.isArray(e)?e:Array.from(e)},toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},compose=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return t.reduceRight(function(e,t){return t(e)},e)}},curry=function e(t){return function(){for(var r=arguments.length,n=Array(r),o=0;o<r;o++)n[o]=arguments[o];return n.length>=t.length?t.apply(void 0,n):function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return e(t).apply(void 0,n.concat(o))}}},isPromise=function(e){return e&&"function"==typeof e.then},isObservable=function(e){return e&&"function"==typeof e.subscribe},toObservable=function(e){return isObservable(e)?e:rxjs.of(e)},switchMap=curry(function(e,t){var r=void 0;return new rxjs.Observable(function(n){var o=!1,i=!1,a=t.subscribe({next:function(t){r&&r.unsubscribe(),r=e(t).subscribe({error:function(e){return n.error(e)},next:function(e){return n.next(e)},complete:function(){i=!0,o&&n.complete()}})},error:function(e){return n.error(e)},complete:function(){o=!0,i&&n.complete()}});return{unsubscribe:function(){r&&r.unsubscribe(),a.unsubscribe()}}})}),all=function(e){return e.length?rxjs.combineLatest.apply(void 0,toConsumableArray(e).concat([function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t}])):rxjs.of([])},blockComplete=function(){return function(e){return new rxjs.Observable(function(t){return e.subscribe({complete:function(){},next:function(e){return t.next(e)},error:function(e){return t.error(e)}})})}},raf=new rxjs.Observable(function(e){var t=!0;return window.requestAnimationFrame(function r(){t&&(e.next(),window.requestAnimationFrame(r))}),{unsubscribe:function(){t=!1}}}),noOp=function(){},createDefaultLifecycle=function(){return{mount:noOp,update:noOp,unmount:noOp}},isEmpty=function(e){return 0!==e&&(!e||"string"==typeof e&&!e.trim())},hasContent=function(e){return!e.length||!e.every(isEmpty)},flatten=function e(t){return Array.isArray(t)?all(t.map(compose(operators.startWith(""),e))).pipe(blockComplete(),operators.filter(hasContent)):isObservable(t)?switchMap(e,t):isPromise(t)?switchMap(e,rxjs.from(t)):toObservable(t)},sharedRaf=operators.share()(raf),createReactiveTag=function(e){return function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return flatten(n).pipe(operators.startWith([]),operators.sample(sharedRaf),operators.map(function(r){return e.apply(void 0,[t].concat(toConsumableArray(r)))}))}};function _objectEntries(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function updateStyle(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};for(var n in _extends({},t,r)){var o=r&&r[n]?r[n]:"";r[n]===t[n]||("-"===n[0]?e.style.setProperty(n,o):e.style[n]=o)}}var VNode=function(){function e(t){var r=t.name,n=t.attrs,o=void 0===n?{}:n,i=t.lifecycle,a=void 0===i?{}:i,u=t.events,c=void 0===u?{}:u,s=t.children,l=void 0===s?{}:s,f=t.key,v=void 0===f?"":f;classCallCheck(this,e),this.name=r,this.attrs=o,this.lifecycle=a,this.events=c,this.children=l,this.key=v}return createClass(e,[{key:"createElement",value:function(e,t){var r=(e=e||"svg"===this.name)?document.createElementNS("http://www.w3.org/2000/svg",this.name):document.createElement(this.name);return this.updateEvents(r,{}),this.updateAttrs(r,{}),this.updateChildren(r,[],e,t),r}},{key:"updateElement",value:function(e,t,r,n){if(t.name!==this.name)return t.removeElement(e),this.createElement(r,n);this.updateEvents(e,t.events),this.updateAttrs(e,t.attrs),this.updateChildren(e,t.children,r,n),this.lifecycle.update(e)}},{key:"removeElement",value:function(e){this.children.map(function(t,r){return t.removeElement(e.childNodes[r])}),this.lifecycle.unmount(e)}},{key:"mount",value:function(e){this.children.map(function(e){return e.mount()}),this.lifecycle.mount(e)}},{key:"updateEvents",value:function(e,t){var r=this,n=!0,o=!1,i=void 0;try{for(var a,u=_objectEntries(this.events)[Symbol.iterator]();!(n=(a=u.next()).done);n=!0){var c=a.value,s=slicedToArray(c,2),l=s[0],f=s[1];t[l]?f!==t[l]&&(e.removeEventListener(l,t[l]),e.addEventListener(l,f)):e.addEventListener(l,f)}}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}var v=_objectEntries(t).filter(function(e){var t=slicedToArray(e,1)[0];return!r.events[t]}),h=!0,m=!1,p=void 0;try{for(var y,d=v[Symbol.iterator]();!(h=(y=d.next()).done);h=!0){var b=y.value,x=slicedToArray(b,2),E=x[0],g=x[1];e.removeEventListener(E,g)}}catch(e){m=!0,p=e}finally{try{!h&&d.return&&d.return()}finally{if(m)throw p}}}},{key:"updateAttrs",value:function(e,t){for(var r in _extends({},t,this.attrs)){var n=this.attrs[r];n===t[r]||(isEmpty(n)?"value"===r&&"INPUT"===e.tagName?e.value="":e.removeAttribute(r):"style"===r?updateStyle(e,t.style,this.attrs.style):"value"===r&&"INPUT"===e.tagName?e.value=n:e.setAttribute(r,n))}}},{key:"updateChildren",value:function(e,t,r,n){for(var o in this.children){var i=this.children[o],a=t[o],u=e.childNodes[o];if(u)n(u,a,i,r);else{var c=i.createElement(r,n);e.appendChild(c),i.mount(c)}}for(var s in[].slice.call(e.childNodes,this.children.length)){var l=parseInt(s)+this.children.length,f=t[l],v=e.childNodes[l];v&&(f.removeElement(v),v.remove())}}}]),e}(),VText=function(){function e(t){var r=t.text;classCallCheck(this,e),this.text=r}return createClass(e,[{key:"createElement",value:function(){return document.createTextNode(this.text)}},{key:"updateElement",value:function(e,t){t.text!==this.text&&(e.textContent=this.text)}},{key:"removeElement",value:function(){}},{key:"mount",value:function(){}}]),e}();function createVTree(e){return new VNode({name:e.nodeName.toLowerCase(),lifecycle:createDefaultLifecycle(),events:{},attrs:{},untouchedAttributes:{},children:Array.prototype.map.call(e.childNodes,function(e){return 3===e.nodeType?new VText({text:e.nodeValue}):createVTree(e)})})}function patch(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:createVTree(e),r=arguments[2],n=arguments[3];if(r.constructor!==t.constructor||r.key!==t.key){t.removeElement(e);var o=r.createElement(n,patch);return e.parentNode.replaceChild(o,e),r.mount(o),o}var i=r.updateElement(e,t,n,patch);return i?(e.parentNode.replaceChild(i,e),r.mount(i,n),i):e}var VPatch=function(){function e(t){classCallCheck(this,e),this.vTree=t}return createClass(e,[{key:"createElement",value:function(){var e;return(e=this.vTree).createElement.apply(e,arguments)}},{key:"updateElement",value:function(){var e;return(e=this.vTree).updateElement.apply(e,arguments)}},{key:"removeElement",value:function(){var e;return(e=this.vTree).removeElement.apply(e,arguments)}},{key:"mount",value:function(){var e;return(e=this.vTree).mount.apply(e,arguments)}}]),e}();function createPropsStream(e){var t=new rxjs.BehaviorSubject(e);return{next:function(e){return t.next(e)},stream:t}}var Component=function(){function e(t){var r=t.name,n=t.untouchedAttributes,o=t.key,i=void 0===o?"":o;classCallCheck(this,e),this.name=r,this.untouchedAttributes=n,this.key=i}return createClass(e,[{key:"createElement",value:function(e,t){var r=this,n=e?document.createElementNS("http://www.w3.org/2000/svg","g"):document.createElement("div");this.state={},this.state.props=createPropsStream(this.untouchedAttributes),this.state.childTree=void 0;var o=this.name(this.state.props.stream);if(!o)throw new Error("Component "+this.name.name+" must return a stream!");return this.state.subscription=o.pipe(flatten,operators.sample(sharedRaf)).subscribe({next:function(o){o instanceof VPatch?r.state.childTree=o.vTree:(n=t(n,r.state.childTree,o,e),r.state.childTree=o)},error:function(e){return console.error(e)}}),n}},{key:"updateElement",value:function(e,t,r,n){if(this.state=t.state,t.name!==this.name)return t.removeElement(e),this.createElement(r,n);this.state.props.next(this.untouchedAttributes)}},{key:"removeElement",value:function(e){this.state.subscription.unsubscribe(),this.state.childTree&&this.state.childTree.removeElement(e)}},{key:"mount",value:function(){}}]),e}(),flatMap=curry(function(e,t){return t.reduce(function(t,r){return t.concat(e(r))},[])});function _objectEntries$1(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries$1(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}var isLifecycle=function(e){return["mount","update","unmount"].includes(e)},isEvent=function(e){return!!e.match(/^on/)},toEventName=function(e){return e.replace(/^on/,"").toLowerCase()},styleToObject=function(e){return e.split(";").reduce(function(e,t){var r=t.split(/:/),n=toArray(r),o=n[0],i=n.slice(1);return o.trim()&&(e[o.trim()]=i.join(":")),e},{})},formatChildren=flatMap(function(e){return Array.isArray(e)?formatChildren(e):[VNode,VText,VPatch,Component].some(function(t){return e instanceof t})?[e]:isEmpty(e)?[]:[new VText({text:""+e})]});function h(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if("function"==typeof e)return new Component({name:e,untouchedAttributes:_extends({},t,{children:r})});var n=_objectEntries$1(t).reduce(function(e,t){var r=slicedToArray(t,2),n=r[0],o=r[1];return"key"===n?e.key=o:isLifecycle(n)&&"function"==typeof o?e.lifecycle[n]=o:isEvent(n)&&"function"==typeof o?e.events[toEventName(n)]=o:e.attrs[n]="style"===n?"object"===(void 0===o?"undefined":_typeof(o))?o:styleToObject(o):o,e},{lifecycle:createDefaultLifecycle(),events:{},attrs:{}}),o=n.key,i=n.lifecycle,a=n.events,u=n.attrs;return new VNode({name:e,attrs:u,lifecycle:i,events:a,children:formatChildren(r),key:o})}var createRenderProcess=function(e){return new rxjs.Observable(function(t){var r=void 0,n=void 0,o=void 0;return e.subscribe({complete:function(){return t.complete()},error:function(e){return t.error(e)},next:function(e){if(!(e instanceof VNode))return t.next(e);var i=e.lifecycle.mount;e.lifecycle.mount=function(e,t){r=e,o=t,i(e)},r?(r=patch(r,n,e,o),t.next(new VPatch(e))):t.next(e),n=e}})})},toRenderProcess=function(e){return function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return createRenderProcess(e.apply(void 0,[t].concat(n)))}},html$1=toRenderProcess(createReactiveTag(createTag(h))),render=function(e,t){var r=t.firstChild,n=void 0;return e.subscribe({next:function(e){e instanceof VPatch?n=e.vTree:(r?patch(r,n,e):(r=e.createElement(!1,patch),t.appendChild(r)),n=e)}})},textTag=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return e.reduce(function(e,t,n){return e+t+(void 0!==r[n]?r[n]:"")},"")},text=createReactiveTag(textTag);exports.default=html$1,exports.text=text,exports.render=render; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var createTag=_interopDefault(require("vdom-tag")),rxjs=require("rxjs"),operators=require("rxjs/operators"),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},slicedToArray=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),toArray=function(e){return Array.isArray(e)?e:Array.from(e)},toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)},compose=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){return t.reduceRight(function(e,t){return t(e)},e)}},curry=function e(t){return function(){for(var r=arguments.length,n=Array(r),o=0;o<r;o++)n[o]=arguments[o];return n.length>=t.length?t.apply(void 0,n):function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return e(t).apply(void 0,n.concat(o))}}},isPromise=function(e){return e&&"function"==typeof e.then},isObservable=function(e){return e&&"function"==typeof e.subscribe},toObservable=function(e){return isObservable(e)?e:rxjs.of(e)},switchMap=curry(function(e,t){var r=void 0;return new rxjs.Observable(function(n){var o=!1,i=!1,a=t.subscribe({next:function(t){r&&r.unsubscribe(),r=e(t).subscribe({error:function(e){return n.error(e)},next:function(e){return n.next(e)},complete:function(){i=!0,o&&n.complete()}})},error:function(e){return n.error(e)},complete:function(){o=!0,i&&n.complete()}});return{unsubscribe:function(){r&&r.unsubscribe(),a.unsubscribe()}}})}),all=function(e){return e.length?rxjs.combineLatest.apply(void 0,toConsumableArray(e.map(toObservable)).concat([function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return t}])):rxjs.of([])},blockComplete=function(){return function(e){return new rxjs.Observable(function(t){return e.subscribe({complete:function(){},next:function(e){return t.next(e)},error:function(e){return t.error(e)}})})}},raf=new rxjs.Observable(function(e){var t=!0;return window.requestAnimationFrame(function r(){t&&(e.next(),window.requestAnimationFrame(r))}),{unsubscribe:function(){t=!1}}}),noOp=function(){},createDefaultLifecycle=function(){return{mount:noOp,update:noOp,unmount:noOp}},isEmpty=function(e){return 0!==e&&(!e||"string"==typeof e&&!e.trim())},hasContent=function(e){return!e.length||!e.every(isEmpty)},flatten=function e(t){return Array.isArray(t)?all(t.map(compose(operators.startWith(""),e))).pipe(blockComplete(),operators.filter(hasContent)):isObservable(t)?switchMap(e,t):isPromise(t)?switchMap(e,rxjs.from(t)):toObservable(t)},sharedRaf=operators.share()(raf),createReactiveTag=function(e){return function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return flatten(n).pipe(operators.startWith([]),operators.sample(sharedRaf),operators.map(function(r){return e.apply(void 0,[t].concat(toConsumableArray(r)))}))}};function _objectEntries(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function updateStyle(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};for(var n in _extends({},t,r)){var o=r&&r[n]?r[n]:"";r[n]===t[n]||("-"===n[0]?e.style.setProperty(n,o):e.style[n]=o)}}var VNode=function(){function e(t){var r=t.name,n=t.attrs,o=void 0===n?{}:n,i=t.lifecycle,a=void 0===i?{}:i,u=t.events,c=void 0===u?{}:u,s=t.children,l=void 0===s?{}:s,f=t.key,v=void 0===f?"":f;classCallCheck(this,e),this.name=r,this.attrs=o,this.lifecycle=a,this.events=c,this.children=l,this.key=v}return createClass(e,[{key:"createElement",value:function(e,t,r){var n=(e=e||"svg"===this.name)?document.createElementNS("http://www.w3.org/2000/svg",this.name):document.createElement(this.name);return this.updateEvents(n,{}),this.updateAttrs(n,{}),this.updateChildren(n,[],e,t,r),n}},{key:"updateElement",value:function(e,t,r,n,o){if(t.name!==this.name)return t.removeElement(e),this.createElement(r,n,o);this.updateEvents(e,t.events),this.updateAttrs(e,t.attrs),this.updateChildren(e,t.children,r,n,o),this.lifecycle.update(e)}},{key:"removeElement",value:function(e){this.children.map(function(t,r){return t.removeElement(e.childNodes[r])}),this.lifecycle.unmount(e)}},{key:"mount",value:function(e){this.children.map(function(e){return e.mount()}),this.lifecycle.mount(e)}},{key:"updateEvents",value:function(e,t){var r=this,n=!0,o=!1,i=void 0;try{for(var a,u=_objectEntries(this.events)[Symbol.iterator]();!(n=(a=u.next()).done);n=!0){var c=a.value,s=slicedToArray(c,2),l=s[0],f=s[1];t[l]?f!==t[l]&&(e.removeEventListener(l,t[l]),e.addEventListener(l,f)):e.addEventListener(l,f)}}catch(e){o=!0,i=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw i}}var v=_objectEntries(t).filter(function(e){var t=slicedToArray(e,1)[0];return!r.events[t]}),h=!0,m=!1,p=void 0;try{for(var y,d=v[Symbol.iterator]();!(h=(y=d.next()).done);h=!0){var b=y.value,x=slicedToArray(b,2),E=x[0],g=x[1];e.removeEventListener(E,g)}}catch(e){m=!0,p=e}finally{try{!h&&d.return&&d.return()}finally{if(m)throw p}}}},{key:"updateAttrs",value:function(e,t){for(var r in _extends({},t,this.attrs)){var n=this.attrs[r];n===t[r]||(isEmpty(n)?"value"===r&&"INPUT"===e.tagName?e.value="":e.removeAttribute(r):"style"===r?updateStyle(e,t.style,this.attrs.style):"value"===r&&"INPUT"===e.tagName?e.value=n:e.setAttribute(r,n))}}},{key:"updateChildren",value:function(e,t,r,n,o){for(var i in this.children){var a=this.children[i],u=t[i],c=e.childNodes[i];if(c)n(c,u,a,r,o);else{var s=a.createElement(r,n,o);e.appendChild(s),a.mount(s)}}for(var l in[].slice.call(e.childNodes,this.children.length)){var f=parseInt(l)+this.children.length,v=t[f],h=e.childNodes[f];h&&(v.removeElement(h),h.remove())}}}]),e}(),VText=function(){function e(t){var r=t.text;classCallCheck(this,e),this.text=r}return createClass(e,[{key:"createElement",value:function(){return document.createTextNode(this.text)}},{key:"updateElement",value:function(e,t){t.text!==this.text&&(e.textContent=this.text)}},{key:"removeElement",value:function(){}},{key:"mount",value:function(){}}]),e}();function createVTree(e){return new VNode({name:e.nodeName.toLowerCase(),lifecycle:createDefaultLifecycle(),events:{},attrs:{},untouchedAttributes:{},children:Array.prototype.map.call(e.childNodes,function(e){return 3===e.nodeType?new VText({text:e.nodeValue}):createVTree(e)})})}function patch(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:createVTree(e),r=arguments[2],n=arguments[3],o=arguments[4];if(r.constructor!==t.constructor||r.key!==t.key){t.removeElement(e);var i=r.createElement(n,patch,o);return e.parentNode.replaceChild(i,e),r.mount(i),i}var a=r.updateElement(e,t,n,patch,o);return a?(e.parentNode.replaceChild(a,e),r.mount(a,n),a):e}var VPatch=function(){function e(t){classCallCheck(this,e),this.vTree=t}return createClass(e,[{key:"createElement",value:function(){var e;return(e=this.vTree).createElement.apply(e,arguments)}},{key:"updateElement",value:function(){var e;return(e=this.vTree).updateElement.apply(e,arguments)}},{key:"removeElement",value:function(){var e;return(e=this.vTree).removeElement.apply(e,arguments)}},{key:"mount",value:function(){var e;return(e=this.vTree).mount.apply(e,arguments)}}]),e}();function createPropsStream(e){var t=new rxjs.BehaviorSubject(e);return{next:function(e){return t.next(e)},stream:t}}var Component=function(){function e(t){var r=t.name,n=t.untouchedAttributes,o=t.key,i=void 0===o?"":o;classCallCheck(this,e),this.name=r,this.untouchedAttributes=n,this.key=i}return createClass(e,[{key:"createElement",value:function(e,t,r){var n=this,o=e?document.createElementNS("http://www.w3.org/2000/svg","g"):document.createElement("div");this.state={},this.state.props=createPropsStream(this.untouchedAttributes),this.state.childTree=void 0;var i=this.name(this.state.props.stream);if(!i)throw new Error("Component "+this.name.name+" must return a stream!");var a="function"==typeof i?i(r):i;return this.state.subscription=a.pipe(flatten,operators.sample(sharedRaf)).subscribe({next:function(r){r instanceof VPatch?n.state.childTree=r.vTree:(o=t(o,n.state.childTree,r,e),n.state.childTree=r)},error:function(e){return console.error(e)}}),o}},{key:"updateElement",value:function(e,t,r,n,o){if(this.state=t.state,t.name!==this.name)return t.removeElement(e),this.createElement(r,n,o);this.state.props.next(this.untouchedAttributes)}},{key:"removeElement",value:function(e){this.state.subscription.unsubscribe(),this.state.childTree&&this.state.childTree.removeElement(e)}},{key:"mount",value:function(){}}]),e}(),flatMap=curry(function(e,t){return t.reduce(function(t,r){return t.concat(e(r))},[])});function _objectEntries$1(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}function _objectEntries$1(e){for(var t=[],r=Object.keys(e),n=0;n<r.length;++n)t.push([r[n],e[r[n]]]);return t}var isLifecycle=function(e){return["mount","update","unmount"].includes(e)},isEvent=function(e){return!!e.match(/^on/)},toEventName=function(e){return e.replace(/^on/,"").toLowerCase()},styleToObject=function(e){return e.split(";").reduce(function(e,t){var r=t.split(/:/),n=toArray(r),o=n[0],i=n.slice(1);return o.trim()&&(e[o.trim()]=i.join(":")),e},{})},formatChildren=flatMap(function(e){return Array.isArray(e)?formatChildren(e):[VNode,VText,VPatch,Component].some(function(t){return e instanceof t})?[e]:isEmpty(e)?[]:[new VText({text:""+e})]});function h(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if("function"==typeof e)return new Component({name:e,untouchedAttributes:_extends({},t,{children:r})});var n=_objectEntries$1(t).reduce(function(e,t){var r=slicedToArray(t,2),n=r[0],o=r[1];return"key"===n?e.key=o:isLifecycle(n)&&"function"==typeof o?e.lifecycle[n]=o:isEvent(n)&&"function"==typeof o?e.events[toEventName(n)]=o:e.attrs[n]="style"===n?"object"===(void 0===o?"undefined":_typeof(o))?o:styleToObject(o):o,e},{lifecycle:createDefaultLifecycle(),events:{},attrs:{}}),o=n.key,i=n.lifecycle,a=n.events,u=n.attrs;return new VNode({name:e,attrs:u,lifecycle:i,events:a,children:formatChildren(r),key:o})}var createRenderProcess=function(e){return new rxjs.Observable(function(t){var r=void 0,n=void 0,o=void 0;return e.subscribe({complete:function(){return t.complete()},error:function(e){return t.error(e)},next:function(e){if(!(e instanceof VNode))return t.next(e);var i=e.lifecycle.mount;e.lifecycle.mount=function(e,t){r=e,o=t,i(e)},r?(r=patch(r,n,e,o),t.next(new VPatch(e))):t.next(e),n=e}})})},toRenderProcess=function(e){return function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return createRenderProcess(e.apply(void 0,[t].concat(n)))}},html$1=toRenderProcess(createReactiveTag(createTag(h))),render=function(e,t,r){var n=t.firstChild,o=void 0;return e.subscribe({next:function(e){e instanceof VPatch?o=e.vTree:(n?patch(n,o,e,!1,r):(n=e.createElement(!1,patch,r),t.appendChild(n)),o=e)}})},textTag=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return e.reduce(function(e,t,n){return e+t+(void 0!==r[n]?r[n]:"")},"")},text=createReactiveTag(textTag);exports.default=html$1,exports.text=text,exports.render=render; |
{ | ||
"name": "evolui", | ||
"version": "1.6.7", | ||
"version": "1.6.8", | ||
"description": "Observable powered templates for asynchronous UIs", | ||
@@ -5,0 +5,0 @@ "main": "lib/evolui.js", |
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
52250
899