This repository was archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
2 lines (2 loc) · 13.2 KB
/
app.js
1
2
!function(){"use strict";var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=(function(){function u(t){this.value=t}function t(i){var r,l;function s(t,e){try{var n=i[t](e),o=n.value;o instanceof u?Promise.resolve(o.value).then(function(t){s("next",t)},function(t){s("throw",t)}):a(n.done?"return":"normal",n.value)}catch(t){a("throw",t)}}function a(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?s(r.key,r.arg):l=null}this._invoke=function(o,i){return new Promise(function(t,e){var n={key:o,arg:i,resolve:t,reject:e,next:null};l?l=l.next=n:(r=l=n,s(o,i))})},"function"!=typeof i.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(t.prototype[Symbol.asyncIterator]=function(){return this}),t.prototype.next=function(t){return this._invoke("next",t)},t.prototype.throw=function(t){return this._invoke("throw",t)},t.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),i=function(){function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}}(),k=0,d=1,S=3,a="http://www.w3.org/1999/xlink",u="http://www.w3.org/2000/svg",r={},l=[];function b(t,e){var n={};for(var o in t)n[o]=t[o];for(var i in e)n[i]=e[i];return n}function s(t){return!Array.isArray(t)&&"object"===(void 0===t?"undefined":c(t))}var h=function t(){o(this,t),this.message="Cannot insert Fragment tag directly into DOM.",this.toString=function(){return this.message}};function f(t,e,n,o,i,r){return{type:t,props:e,children:n,element:o,key:i,flag:r}}function p(t,e){return f(t,r,l,e,null,S)}function m(t){return f(t.nodeName.toLowerCase(),r,l.map.call(t.childNodes,e),t,null,k)}function e(t){return 3===t.nodeType?p(t.nodeValue,t):m(t)}function v(t,e){for(var n=void 0,o=[],i=[],r=arguments.length,l=Array(2<r?r-2:0),s=2;s<r;s++)l[s-2]=arguments[s];for(var a=l.length,u=(e=e||{}).key;0<a--;)o.push(l[a]);for(null!=e.children&&(o.length<=0&&o.push(e.children),delete e.children);0<o.length;)if(Array.isArray(n=o.pop()))for(a=n.length;0<a--;)o.push(n[a]);else!1===n||!0===n||null==n||i.push("object"===(void 0===n?"undefined":c(n))?n:p(n));return delete e.key,"function"==typeof t?t(e,e.children=i):f(t,e,i,null,u,d)}function y(t){return t.currentTarget.events[t.type](t)}function A(t){return null==t?null:t.key}function N(t,e,n,o,i){if("style"!==e||"object"!==(void 0===o?"undefined":c(o))||Array.isArray(o)){if("key"!==e)if("className"===e&&(e="class"),"o"===e[0]&&"n"===e[1])t.events||(t.events={}),null==(t.events[e=e.slice(2).toLowerCase()]=o)?t.removeEventListener(e,y):null==n&&t.addEventListener(e,y);else{var r=null==o||!1===o||"no"===o||"off"===o;e in t&&"list"!==e&&"type"!==e&&"draggable"!==e&&"spellcheck"!==e&&"translate"!==e&&!i?(t[e]=null==o?"":o,r&&t.removeAttribute(e)):"xlink-href"===e||"xlinkHref"===e?(t.setAttributeNS(a,"href",o),t.setAttribute("href",o)):r?t.removeAttribute(e):t.setAttribute(e,o)}}else for(var l in b(n,o)){var s=null==o||null==o[l]?"":o[l];"-"===l[0]?t[e].setProperty(l,s):t[e][l]=s}}function M(t,e,n){var o=void 0;o=t.flag===S?document.createTextNode(t.type):(n=n||"svg"===t.type)?document.createElementNS(u,t.type):document.createElement(t.type);var i=t.props;i.onmount&&e.push(function(){i.onmount(o)});for(var r=0,l=t.children.length;r<l;r++)o.appendChild(M(t.children[r],e,n));for(var s in i)N(o,s,null,i[s],n);return t.element=o}function I(t,e){function n(){t&&t.nodeType&&t.removeChild(function t(e){for(var n=0,o=e.children.length;n<o;n++)t(e.children[n]);return e.element}(e))}var o=e.props&&e.props.onunmount;null!=o?o(n,e.element):n()}function O(t,e,n,o,i,r){if(o===n);else if(null!=n&&n.flag===S&&o.flag===S)n.type!==o.type&&(e.nodeValue=o.type);else if(null==n||n.type!==o.type){var l=t.insertBefore(M(o,i,r),e);null!=n&&I(t,n),e=l}else{!function(t,e,n,o,i,r){for(var l in b(e,n))("value"===l||"checked"===l?t[l]:e[l])!==n[l]&&N(t,l,e[l],n[l],i);var s=r?n.onmount:n.onupdate;null!=s&&o.push(function(){s(t,e,n)})}(e,n.props,o.props,i,r=r||"svg"===o.type,n.flag===k);for(var s=void 0,a=void 0,u=void 0,c=n.children,d=0,h=c.length-1,f=void 0,p=o.children,m=0,v=p.length-1;m<=v&&d<=h&&(u=A(c[d]),f=A(p[m]),null!=u&&u===f);)O(e,c[d].element,c[d],p[m],i,r),d++,m++;for(;m<=v&&d<=h&&(u=A(c[h]),f=A(p[v]),null!=u&&u===f);)O(e,c[h].element,c[h],p[v],i,r),h--,v--;if(h<d)for(;m<=v;)e.insertBefore(M(p[m++],i,r),(a=c[d])&&a.element);else if(v<m)for(;d<=h;)I(e,c[d++]);else{for(var y=function(t,e,n){for(var o={},i=void 0,r=void 0;e<=n;e++)null!=(i=(r=t[e]).key)&&(o[i]=r);return o}(c,d,h),g={};m<=v;)u=A(a=c[d]),f=A(p[m]),g[u]||null!=f&&f===A(c[d+1])?(null==u&&I(e,a),d++):null==f||n.flag===k?(null==u&&(O(e,a&&a.element,a,p[m],i,r),m++),d++):(u===f?(O(e,a.element,a,p[m],i,r),g[f]=!0,d++):null!=(s=y[f])?(O(e,e.insertBefore(s.element,a&&a.element),s,p[m],i,r),g[f]=!0):O(e,a&&a.element,null,p[m],i,r),m++);for(;d<=h;)null==A(a=c[d++])&&I(e,a);for(var w in y)null==g[w]&&I(e,y[w])}}return o.element=e,o}function g(t,e,n){"string"==typeof n&&(n=document.querySelector(n));var o=[];if(O(n,n.children[0],e,t,o),t!==e)for(;0<o.length;)o.pop()();return t}var n=(new Date).getTime().toString(16),w=function(){function e(t){o(this,e),t||(t={}),this.props=t,this.selector=t.container||"body",t.render&&(this.render=t.render),t.state&&(this.state=t.state),this.selector&&(this.container=document.querySelector(this.selector)),this.currentVNode=null,this.componentShouldUpdate=!0,this.isMounted=!1,this.element=null,this.hydrate=t.hydrate||null,t.componentWillMount&&(this.componentWillMount=t.componentWillMount),t.componentDidMount&&(this.componentDidMount=t.componentDidMount),t.componentWillUpdate&&(this.componentWillUpdate=t.componentWillUpdate),t.componentDidUpdate&&(this.componentDidUpdate=t.componentDidUpdate),t.componentWillUnmount&&(this.componentWillUnmount=t.componentWillUnmount)}return i(e,[{key:"noop",value:function(){}},{key:"componentWillMount",value:function(t){t&&"function"==typeof t&&t.call(t,this)}},{key:"componentDidMount",value:function(){this.noop()}},{key:"componentWillUpdate",value:function(t){t&&"function"==typeof t&&t.call(t,this)}},{key:"componentDidUpdate",value:function(){this.noop()}},{key:"componentWillUnmount",value:function(t){t&&"function"==typeof t&&t.call(t,this)}},{key:"render",value:function(t){return t}},{key:"setState",value:function(t){if("function"==typeof t){var e=void 0;e=s(this.state)?b(r,this.state):Array.isArray(this.state)?l.concat(l,this.state):this.state;var n=t.call(this,e);n&&(this.state=n)}else if(s(this.state)&&s(t)){var o=b(this.state,t);this.state=o}else this.state=t}},{key:"update",value:function(t){if(this.render&&(this.componentShouldUpdate||!this.isMounted)){var e=this.state;!0!==t&&t&&(e=t),this.container&&"string"==typeof this.container&&(this.selector=this.container,this.container=document.querySelector(this.container)),this.hydrate&&!this.isMounted&&("string"==typeof this.hydrate&&(this.hydrate=document.querySelector(this.hydrate)),this.currentVNode=m(this.hydrate));var n,o,i=this.render(e),r=this;if(!this.isMounted)return this.currentVNode?(this.oldVNode=i,this.currentVNode=g(i,this.currentVNode,this.container),this.element=this.currentVNode.element,this.isMounted=!0,this.componentDidMount()):this.componentWillMount(function(){r.oldVNode=i,r.currentVNode=function(t,e,n){"string"==typeof e&&(e=document.querySelector(e)),e||(e=document.body);var o=[];if(Array.isArray(t))throw new h;if(n)"string"==typeof n&&(n=document.querySelector(n)),g(t,m(n),e);else{var i=M(t,o);e.appendChild(i),t.element=i}for(t.element.isMounted=!0;0<o.length;)o.pop()();return t}(i,r.container),r.element=r.currentVNode.element,r.isMounted=!0,r.componentDidMount()}),void(this.container&&1===this.container.nodeType||console.error("The container for this class component is not a valid DOM node. Check the selector provided for the class to make sure it is a valid CSS selector and that the container exists in the DOM. You might be targeting a nonexistent node."));if(n=i,o=this.oldVNode,JSON.stringify(n)!==JSON.stringify(o))this.componentWillUpdate(function(){r.oldVNode=r.render(e),r.currentVNode=g(i,r.currentVNode,r.container),r.element=r.currentVNode.element,r.isMounted=!0,r.componentDidUpdate()})}}},{key:"unmount",value:function(){if(this.element){var e=this;this.componentWillUnmount(function(){for(var t in e.container.removeChild(e.element),e)delete e[t];e.__proto__=null})}}},{key:"state",get:function(){return this[n]},set:function(t){var e=this;this[n]=t,setTimeout(function(){return e.update()},1e3/60)}}]),e}(),t=new w({container:"header",render:function(t){return v("nav",null,v("h1",null,t))}});function T(){return Math.floor(1e8*Math.random()+1e3*Math.random())}function x(t){var e=t.props,n=t.item;return v("li",{class:n.active?"active":"","data-id":n.id},v("button",{class:"set-state",onclick:e.setActiveState},v("svg",{width:"20px",height:"20px",viewBox:"0 0 20 20",version:"1.1"},v("g",{id:"Page-1",stroke:"none","stroke-width":"1",fill:"none","fill-rule":"evenodd"},v("g",{id:"selection-indicator"},v("path",{d:"M2,13 L9.9294326,16.8406135 L17.1937075,1.90173332",id:"checkmark",stroke:"#007AFF","stroke-width":"2"}))))),v("h3",null,n.value),v("button",{class:"delete",onclick:e.deleteItem},"X"))}function L(t){var e=t.props;return v("footer",null,v("div",{id:"totals-view"},v("span",null,1<e.itemsToShow.length?e.itemsToShow.length+" items":e.itemsToShow.length+" item"," left.")),v("p",null,"Show: "),v("div",{id:"show-todo-state"},v("button",{onclick:e.showAll,id:"show-all",class:"selected"},"All"),v("button",{onclick:e.showActive,id:"show-active",class:""},"Active"),v("button",{onclick:e.showCompleted,id:"show-completed",class:""},"Completed")))}function C(e){return v("div",{class:"parent-view"},v("p",{class:"add-todo"},v("input",{type:"text"}),v("button",{class:"addItem",onclick:e.addItem},"Add Item")),v("ul",{class:"todo-list"},e.data.map(function(t){return v(x,{props:e.component,item:t})})),v(L,{props:e.component}))}var D=function(t){function n(t){o(this,n);var e=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t));return e.setActiveState=e.setActiveState.bind(e),e.deleteItem=e.deleteItem.bind(e),e.itemsToShow=[],e.showAll=e.showAll.bind(e),e.showActive=e.showActive.bind(e),e.showCompleted=e.showCompleted.bind(e),e.addItem=e.addItem.bind(e),e}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(n,w),i(n,[{key:"render",value:function(t){var e=this,n=this.state;return this.itemsToShow=[],n.map(function(t){!0===t.active&&e.itemsToShow.push(t)}),v(C,{component:this,data:this.state,addItem:function(){return e.addItem()}})}},{key:"componentDidMount",value:function(){this.input=this.element.querySelector("input")}},{key:"setActiveState",value:function(t){var e=t.target.closest("li").dataset.id,n=this.state,o=n.findIndex(function(t){return t.id==e});n[o].active=!n[o].active,this.setState(n),localStorage.setItem("todo-list",JSON.stringify(n))}},{key:"deleteItem",value:function(t){var e=t.target.closest("li").dataset.id,n=this.state,o=n.findIndex(function(t){return t.id==e});n.splice(o,1),this.setState(n),localStorage.setItem("todo-list",JSON.stringify(n))}},{key:"showAll",value:function(t){this.setSelectedStateOfButtons(t),this.getAllListItems().map(function(t){return t.classList.remove("hidden")})}},{key:"showActive",value:function(t){this.setSelectedStateOfButtons(t);var n=this.getAllListItems();this.state.map(function(t,e){t.active?n[e].classList.remove("hidden"):n[e].classList.add("hidden")})}},{key:"showCompleted",value:function(t){this.setSelectedStateOfButtons(t);var n=this.getAllListItems();this.state.map(function(t,e){t.active?n[e].classList.add("hidden"):n[e].classList.remove("hidden")})}},{key:"setSelectedStateOfButtons",value:function(t){for(var e=t.target,n=0;n<e.parentNode.children.length;n++)e.parentNode.children[n].className="";e.className="selected"}},{key:"addItem",value:function(){var e=this.input.value;e?(this.setState(function(t){return t.push({active:!0,value:e,id:T()}),t}),localStorage.setItem("todo-list",JSON.stringify(this.state)),this.input.value=""):alert("Please provide a todo to add!")}},{key:"getAllListItems",value:function(){return Array.prototype.slice.call(this.element.querySelectorAll("li"))}}]),n}();t.state="Composi Todo List";var U=new D({container:"section",state:[{active:!0,value:"Take a nap",id:T()},{active:!1,value:"Eat a snack",id:T()},{active:!0,value:"Talk with Mom",id:T()}]});document.addEventListener("DOMContentLoaded",function(){setTimeout(function(){var t,e=(t=localStorage.getItem("todo-list"),JSON.parse(t));e&&e.length?U.state=e:U.update()})})}();
//# sourceMappingURL=app.js.map