superglue.js
Version:
Simple web application platform using superviews.js and supermodels.js together with browserify
1 lines • 28.4 kB
JavaScript
(function e(t,r,n){function i(o,s){if(!r[o]){if(!t[o]){var u=typeof require=="function"&&require;if(!s&&u)return u(o,!0);if(a)return a(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[o]={exports:{}};t[o][0].call(c.exports,function(e){var r=t[o][1][e];return i(r?r:e)},c,c.exports,e,t,r,n)}return r[o].exports}var a=typeof require=="function"&&require;for(var o=0;o<n.length;o++)i(n[o]);return i})({1:[function(e,t,r){t.exports={items:[{productId:"dsf1f",quantity:2},{productId:"dr6hb",quantity:5},{productId:"sdr4f",quantity:1}]}},{}],2:[function(e,t,r){var n=e("supermodels.js");var i=e("../incremental-dom").patch;var a=e("../helpers");var o=e("./template.html");var s=e("./products-data");var u=e("./basket-data");var l={productId:a.rndstr,productName:String,price:Number,image:String,discountPercent:Number,get cost(){return this.price-this.price*this.discountPercent}};var c=[l];var f={items:[{id:a.rndstr,productId:a.rndstr,quantity:Number,get cost(){var e=this.product;return this.quantity*(e.price-e.price*e.discountPercent)},get product(){var e=this.productId;var t=this.__ancestors[this.__ancestors.length-1];return t.products.filter(function(t){return t.productId===e})[0]}}],get totalCost(){var e=0;for(var t=0,r=this.items.length;t<r;t++){e+=this.items[t].cost}return e},get totalQuantity(){var e=0;for(var t=0,r=this.items.length;t<r;t++){e+=this.items[t].quantity}return e}};var p=n(f);var d=n(c);var v={basket:p,products:d};var h=n(v);window.apps=[];t.exports=function(e){var t=new h({basket:new p(u),products:new d(s)});function r(){i(e,o,t)}r();t.on("change",r);window.apps.push(t)}},{"../helpers":7,"../incremental-dom":8,"./basket-data":1,"./products-data":4,"./template.html":5,"supermodels.js":12}],3:[function(e,t,r){t.exports=function e(t){elementOpen("h3");text(" Total lines "+t.items.length+", total quantity "+t.totalQuantity+" ");elementClose("h3")}},{}],4:[function(e,t,r){t.exports=[{productId:"dsf1f",productName:"Apple iPod touch 32GB 5th Generation - White",price:190.5,discountPercent:0,image:"basket/img/apple.jpg"},{productId:"dr6hb",productName:"Samsung Galaxy Tab 3 7-inch - (Black, Wi-Fi)",price:110,discountPercent:.2,image:"basket/img/samsung.jpg"},{productId:"sdr4f",productName:"Bose QuietComfort 20 Acoustic Noise Cancelling Headphones",price:250,discountPercent:.125,image:"basket/img/bose.jpg"}]},{}],5:[function(e,t,r){t.exports=function t(r){var t=r.basket;var n=r.products;var i=e("./lines-summary.html");var a=e("./total-summary.html");function o(e){var r=t.items;var n=r.find(function(t){return t.productId===e.productId});if(n){n.quantity++}else{var i=r.create();i.productId=e.productId;i.quantity=1;r.push(i)}}function s(e){t.items.splice(e,1)}if(t.items.length){elementOpen("table",null,["class","table"]);elementOpen("thead");elementOpen("tr");elementOpen("th");text("id");elementClose("th");elementOpen("th");text("productId");elementClose("th");elementOpen("th");text("productName");elementClose("th");elementOpen("th");text("quantity");elementClose("th");elementOpen("th");text("price");elementClose("th");elementOpen("th");text("discountPercent");elementClose("th");elementOpen("th");text("cost");elementClose("th");elementOpen("th");i(t);elementClose("th");elementClose("tr");elementClose("thead");elementOpen("tbody");(Array.isArray(t.items)?t.items:Object.keys(t.items)).forEach(function(e,t){elementOpen("tr",e.id);elementOpen("td");text(""+e.id+"");elementClose("td");elementOpen("td");text(""+e.product.productId+"");elementClose("td");elementOpen("td");text(""+e.product.productName+"");elementClose("td");elementOpen("td");elementOpen("input",null,["type","number"],"value",e.quantity,"onchange",function(t){t.preventDefault();var r=this;e.quantity=this.value});elementClose("input");elementClose("td");elementOpen("td");text(""+e.product.price+"");elementClose("td");elementOpen("td");text(""+(e.product.discountPercent*100+" %")+"");elementClose("td");elementOpen("td");text(""+e.cost.toFixed(2)+"");elementClose("td");elementOpen("td");elementOpen("button",null,["class","btn btn-sm btn-danger"],"onclick",function(e){e.preventDefault();var r=this;s(t)});text("Remove");elementClose("button");elementClose("td");elementClose("tr")},t.items);elementClose("tbody");a(t);elementClose("table")}if(!t.items.length){text(" You have no items in your basket! ")}(Array.isArray(n)?n:Object.keys(n)).forEach(function(e,t){elementOpen("div",t,["style","width: 33%; float: left;"]);elementOpen("div");text(""+e.productId+"");elementClose("div");elementOpen("div");text(""+e.productName+"");elementClose("div");elementOpen("div");text(""+e.price+"");elementClose("div");elementOpen("div");text(""+(e.discountPercent*100+" %")+"");elementClose("div");elementOpen("div");text(""+e.cost+"");elementClose("div");elementOpen("img",null,["style","max-width: 240px; max-height: 200px;"],"src",e.image);elementClose("img");elementOpen("button",null,["class","btn btn-sm btn-success"],"onclick",function(t){t.preventDefault();var r=this;o(e)});text("Add to basket");elementClose("button");elementClose("div")},n);(Array.isArray(r)?r:Object.keys(r)).forEach(function(e,t){elementOpen("div",e);elementOpen("span");text(""+e+"");elementClose("span");elementOpen("span");text(""+t+"");elementClose("span");elementClose("div")},r);elementOpen("pre");elementOpen("code");text(" "+JSON.stringify(r,null,2)+" ");elementClose("code");elementOpen("pre");elementClose("pre");elementClose("pre")}},{"./lines-summary.html":3,"./total-summary.html":6}],6:[function(e,t,r){t.exports=function e(t){elementOpen("tfoot");elementOpen("tr");elementOpen("td",null,["colspan","8"]);elementOpen("h3");text(" "+t.totalCost+" ");elementClose("h3");elementClose("td");elementClose("tr");elementClose("tfoot")}},{}],7:[function(e,t,r){function n(){return Math.random().toString(36).substr(2,5)}t.exports={rndstr:{__value:n}}},{}],8:[function(e,t,r){(function(e,n){typeof r==="object"&&typeof t!=="undefined"?n(r):typeof define==="function"&&define.amd?define(["exports"],n):n(e.IncrementalDOM={})})(this,function(e){"use strict";var t;var r=function(){return t};var n=function(e){t=e};function i(e,t){this.attrs={};this.attrsArr=[];this.newAttrs={};this.key=t;this.keyMap=null;this.keyMapValid=true;this.lastVisitedChild=null;this.nodeName=e;this.text=null}var a=function(e,t,r){var n=new i(t,r);e["__incrementalDOMData"]=n;return n};var o=function(e){var t=e["__incrementalDOMData"];if(!t){var r=e.nodeName.toLowerCase();var n=null;if(e instanceof Element){n=e.getAttribute("key")}t=a(e,r,n)}return t};var s=function(e,t,r){if(r==null){e.removeAttribute(t)}else{e.setAttribute(t,r)}};var u=function(e,t,r){e[t]=r};var l=function(e,t,r){if(typeof r==="string"){e.style.cssText=r}else{e.style.cssText="";for(var n in r){e.style[n]=r[n]}}};var c=function(e,t,r){var n=typeof r;if(n==="object"||n==="function"){u(e,t,r)}else{s(e,t,r)}};var f=function(e,t,r){var n=o(e);var i=n.attrs;if(i[t]===r){return}var a=d[t]||d.__all;a(e,t,r);i[t]=r};var p={applyAttr:s,applyProp:u,applyStyle:l};var d={__all:c,style:l};var v="http://www.w3.org/2000/svg";var h=function(e){if(e==="svg"){r().enterNamespace(v)}else if(e==="foreignObject"){r().enterNamespace(undefined)}};var m=function(e){if(e==="svg"||e==="foreignObject"){r().exitNamespace()}};var _=function(e){if(e==="svg"){return v}return r().getCurrentNamespace()};var y=function(e,t,r,n){var i=_(t);var o;if(i){o=e.createElementNS(i,t)}else{o=e.createElement(t)}a(o,t,r);if(n){for(var s=0;s<n.length;s+=2){f(o,n[s],n[s+1])}}return o};var g=function(e,t,r,n){if(t==="#text"){return e.createTextNode("")}return y(e,t,r,n)};var b=function(e){var t={};var r=e.children;var n=r.length;for(var i=0;i<n;i+=1){var a=r[i];var s=o(a).key;if(s){t[s]=a}}return t};var O=function(e){var t=o(e);if(!t.keyMap){t.keyMap=b(e)}return t.keyMap};var C=function(e,t){return O(e)[t]};var w=function(e,t,r){O(e)[t]=r};if(undefined!=="production"){var x=function(e,t,r){var n=o(e).nodeName;if(n!==t){throw new Error('Was expecting node with key "'+r+'" to be a '+t+", not a "+n+".")}}}var k=function(e,t,r){var n=o(e);return r==n.key&&t===n.nodeName};var N=function(e,t,n){var i=r();var a=i.currentNode;var s=i.getCurrentParent();var u;if(a&&k(a,e,t)){u=a}else{var l=t&&C(s,t);if(l){if(undefined!=="production"){x(l,e,t)}u=l}else{u=g(i.doc,e,t,n);if(t){w(s,t,u)}}if(a&&o(a).key){s.replaceChild(u,a);o(s).keyMapValid=false}else{s.insertBefore(u,a)}i.currentNode=u}return u};var A=function(e){var t=o(e);var r=t.keyMap;var n=t.keyMapValid;var i=e.lastChild;var a=t.lastVisitedChild;t.lastVisitedChild=null;if(i===a&&n){return}while(i!==a){e.removeChild(i);i=e.lastChild}for(var s in r){if(!r[s].parentNode){delete r[s]}}t.keyMapValid=true};var j=function(e){var t=o(e);h(t.nodeName)};var S=function(e){var t=o(e);m(t.nodeName)};var E=function(e){var t=r();var n=t.getCurrentParent();var i=o(n);i.lastVisitedChild=e};var V=function(){var e=r();j(e.currentNode);e.firstChild()};var P=function(){var e=r();E(e.currentNode);e.nextSibling()};var D=function(){var e=r();e.parentNode();S(e.currentNode)};function I(e){this.stack_=[];this.currentNode=e;this.doc=e.ownerDocument;this.nsStack_=[undefined]}I.prototype.getCurrentParent=function(){return this.stack_[this.stack_.length-1]};I.prototype.getCurrentNamespace=function(){return this.nsStack_[this.nsStack_.length-1]};I.prototype.enterNamespace=function(e){this.nsStack_.push(e)};I.prototype.exitNamespace=function(){this.nsStack_.pop()};I.prototype.firstChild=function(){this.stack_.push(this.currentNode);this.currentNode=this.currentNode.firstChild};I.prototype.nextSibling=function(){this.currentNode=this.currentNode.nextSibling};I.prototype.parentNode=function(){this.currentNode=this.stack_.pop()};if(undefined!=="production"){var q=function(e){var t=r().getCurrentParent();if(!t){return}var n=[];while(t&&t!==e){n.push(t.nodeName.toLowerCase());t=t.parentNode}throw new Error("One or more tags were not closed:\n"+n.join("\n"))}}e.patch=function(e,t,i){var a=r();n(new I(e));V();t(i);D();A(e);if(undefined!=="production"){q(e)}n(a)};var M=3;var L=[];if(undefined!=="production"){var R=false;var B=function(){if(R){throw new Error("Was not expecting a call to attr or elementOpenEnd, "+"they must follow a call to elementOpenStart.")}};var T=function(){if(!R){throw new Error("Was expecting a call to attr or elementOpenEnd. "+"elementOpenStart must be followed by zero or more calls to attr, "+"then one call to elementOpenEnd.")}};var z=function(e){var t=r().getCurrentParent();var n=o(t);if(e!==n.nodeName){throw new Error("Received a call to close "+e+" but "+n.nodeName+" was open.")}};var F=function(){R=true};var U=function(){R=false}}e.elementOpen=function(e,t,r,n){if(undefined!=="production"){B()}var i=N(e,t,r);var a=o(i);var s=a.attrsArr;var u=false;var l=M;var c=0;for(;l<arguments.length;l+=1,c+=1){if(s[c]!==arguments[l]){u=true;break}}for(;l<arguments.length;l+=1,c+=1){s[c]=arguments[l]}if(c<s.length){u=true;s.length=c}if(u){var p=a.newAttrs;for(var d in p){p[d]=undefined}for(var l=M;l<arguments.length;l+=2){p[arguments[l]]=arguments[l+1]}for(var d in p){f(i,d,p[d])}}V();return i};e.elementOpenStart=function(e,t,r){if(undefined!=="production"){B();F()}L[0]=e;L[1]=t;L[2]=r};e.attr=function(e,t){if(undefined!=="production"){T()}L.push(e,t)};e.elementOpenEnd=function(){if(undefined!=="production"){T();U()}var t=e.elementOpen.apply(null,L);L.length=0;return t};e.elementClose=function(e){if(undefined!=="production"){B();z(e)}D();var t=r().currentNode;A(t);P();return t};e.elementVoid=function(t,r,n,i){if(undefined!=="production"){B()}var a=e.elementOpen.apply(null,arguments);e.elementClose.apply(null,arguments);return a};e.text=function(e,t){if(undefined!=="production"){B()}var r=N("#text",null);var n=o(r);if(n.text!==e){n.text=e;var i=e;for(var a=1;a<arguments.length;a+=1){i=arguments[a](i)}r.data=i}P()};e.mutators={attributes:d};e.defaults={attributes:p}})},{}],9:[function(e,t,r){var n=e("./incremental-dom");var i=n.patch;var a=n.elementOpen;var o=n.elementVoid;var s=n.elementClose;var u=n.text;var l=e("./basket");var c=e("./todo");window.patch=i;window.elementOpen=a;window.elementVoid=o;window.elementClose=s;window.text=u;window.basket=l;window.todo=c},{"./basket":2,"./incremental-dom":8,"./todo":10}],10:[function(e,t,r){var n=e("./todo.html");var i=e("../incremental-dom").patch;var a=e("supermodels.js");var o=e("../helpers");var s=a({id:o.rndstr,text:String,completed:Boolean});var u=a([s]);t.exports=function(e){var t=new u([{text:"Phone mum",completed:false},{text:"Do shopping",completed:true},{text:"Write email to Brian",completed:true}]);function r(){i(e,n,t)}r();t.on("change",r)}},{"../helpers":7,"../incremental-dom":8,"./todo.html":11,"supermodels.js":12}],11:[function(e,t,r){t.exports=function e(e){function t(t){var r=e.create();r.text=t.newTodo.value;e.push(r);t.newTodo.select()}function r(t){var r=e.length;for(var n=r-1;n>=0;n--){if(e[n].completed){e.splice(n,1)}}}function n(t){e.forEach(function(e){e.completed=t})}function i(){return e.filter(function(e){return e.completed}).length}elementOpen("table");elementOpen("thead");elementOpen("tr");elementOpen("td");elementClose("td");elementOpen("td");elementOpen("form",null,null,"onsubmit",function(e){e.preventDefault();var r=this;t(r)});elementOpen("input",null,["type","text","name","newTodo","class","form-control","placeholder","Enter new todo"]);elementClose("input");elementClose("form");elementClose("td");elementClose("tr");elementClose("thead");elementOpen("tbody");(Array.isArray(e)?e:Object.keys(e)).forEach(function(e,t){elementOpen("tr",e.id);elementOpen("td");text(""+(t+1)+".");elementClose("td");elementOpen("td");elementOpen("input",null,["type","text","class","form-control"],"value",e.text,"onkeyup",function(t){t.preventDefault();var r=this;e.text=this.value},"style",{borderColor:e.text?"":"red",textDecoration:e.completed?"line-through":""});elementClose("input");elementClose("td");elementOpen("td");elementOpen("input",null,["type","checkbox"],"checked",e.completed||undefined,"onchange",function(t){t.preventDefault();var r=this;e.completed=this.checked});elementClose("input");elementClose("td");elementClose("tr")},e);elementOpen("tr");elementClose("tr");elementClose("tbody");elementOpen("tfoot");elementOpen("tr");elementOpen("td");text("Total "+e.length+"");elementClose("td");elementOpen("td");elementClose("td");elementOpen("td");if(i()){elementOpen("button",null,["class","btn btn-sm btn-danger"],"onclick",function(e){e.preventDefault();var t=this;r()});text("Clear completed "+i()+"");elementClose("button")}elementClose("td");elementClose("tr");elementClose("tfoot");elementClose("table");elementOpen("pre");text(""+JSON.stringify(e,null,2)+"");elementClose("pre")}},{}],12:[function(e,t,r){t.exports=e("./lib/supermodels")},{"./lib/supermodels":22}],13:[function(e,t,r){"use strict";var n=e("./util");var i=e("./factory");function a(e){var t=n.isConstructor(e);var r=n.isSupermodelConstructor(e);var i=n.isArray(e);if(t||r||i){return{__type:e}}var a=!n.isObject(e);if(a){return{__value:e}}return e}function o(e){e=a(e);var t="__validators";var r="__value";var s="__type";var u="__displayName";var l="__get";var c="__set";var f="__enumerable";var p="__configurable";var d="__writable";var v=[t,r,s,u,l,c,f,p,d];var h={from:e,type:e[s],value:e[r],validators:e[t]||[],enumerable:e[f]!==false,configurable:!!e[p],writable:e[d]!==false,displayName:e[u],getter:e[l],setter:e[c]};var m=h.type;if(n.isSimpleConstructor(m)){h.isSimple=true;h.cast=function(e){return n.cast(e,m)}}else if(n.isSupermodelConstructor(m)){h.isReference=true}else if(h.value){h.isSimple=true}else{var _=Object.keys(e);var y=_.filter(function(e){return v.indexOf(e)===-1});if(y.length){var g={};var b;y.forEach(function(t){var r=Object.getOwnPropertyDescriptor(e,t);var i;if(r.get||r.set){i={__get:r.get,__set:r.set}}else{i=e[t]}if(!n.isConstructor(i)&&!n.isSupermodelConstructor(i)&&n.isFunction(i)){if(!b){b={}}b[t]=i}else{g[t]=o(i)}});h.defs=g;h.proto=b}if(m===Array||n.isArray(m)){h.isArray=true;if(m.length>0){h.def=o(m[0])}}else if(y.length===0){h.isSimple=true}}h.create=i(h);return h}t.exports=o},{"./factory":17,"./util":23}],14:[function(e,t,r){"use strict";t.exports=function(e){var t=[];var r=function(){var r=Array.prototype.pop.apply(t);e("pop",t,{value:r});return r};var n=function(){var r=Array.prototype.push.apply(t,arguments);e("push",t,{value:r});return r};var i=function(){var r=Array.prototype.shift.apply(t);e("shift",t,{value:r});return r};var a=function(){var r=Array.prototype.sort.apply(t,arguments);e("sort",t,{value:r});return r};var o=function(){var r=Array.prototype.unshift.apply(t,arguments);e("unshift",t,{value:r});return r};var s=function(){var r=Array.prototype.reverse.apply(t);e("reverse",t,{value:r});return r};var u=function(){if(!arguments.length){return}var r=Array.prototype.splice.apply(t,arguments);e("splice",t,{value:r,removed:r,added:Array.prototype.slice.call(arguments,2)});return r};t.pop=t.pop&&r;t.push=t.push&&n;t.shift=t.shift&&i;t.unshift=t.unshift&&o;t.sort=t.sort&&a;t.reverse=t.reverse&&s;t.splice=t.splice&&u;t.update=function(r,n){var i=t[r];var a=t[r]=n;e("update",t,{index:r,value:a,oldValue:i});return a};return t}},{}],15:[function(e,t,r){"use strict";t.exports=function e(t,r,n,i){this.name=t;this.path=r;this.target=n;if(i){this.detail=i}}},{}],16:[function(e,t,r){"use strict";t.exports=n;function n(e){var t=e||this;if(e){t=i(e);return t}}function i(e){for(var t in n.prototype){e[t]=n.prototype[t]}return e}n.prototype.on=n.prototype.addEventListener=function(e,t){(this.__callbacks[e]=this.__callbacks[e]||[]).push(t);return this};n.prototype.once=function(e,t){function r(){this.off(e,r);t.apply(this,arguments)}r.fn=t;this.on(e,r);return this};n.prototype.off=n.prototype.removeEventListener=n.prototype.removeAllListeners=function(e,t){if(arguments.length===0){this.__callbacks={};return this}var r=this.__callbacks[e];if(!r){return this}if(arguments.length===1){delete this.__callbacks[e];return this}var n;for(var i=0;i<r.length;i++){n=r[i];if(n===t||n.fn===t){r.splice(i,1);break}}return this};n.prototype.emit=function(e){var t=[].slice.call(arguments,1);var r=this.__callbacks[e];if(r){r=r.slice(0);for(var n=0,i=r.length;n<i;++n){r[n].apply(this,t)}}return this};n.prototype.listeners=function(e){return this.__callbacks[e]||[]};n.prototype.hasListeners=function(e){return!!this.listeners(e).length}},{}],17:[function(e,t,r){"use strict";var n=e("./util");var i=e("./proto");var a=e("./wrapper");function o(e,t){var r={};var n={__:{value:r},__def:{value:e},__parent:{value:t,writable:true},__callbacks:{value:{},writable:true}};return n}function s(e){var t=e.__def.defs;for(var r in t){u(e,r,t[r])}}function u(e,t,r){var n={get:function(){return this.__get(t)},enumerable:r.enumerable,configurable:r.configurable};if(r.writable){n.set=function(e){this.__setNotifyChange(t,e)}}Object.defineProperty(e,t,n);e.__[t]=r.create(e)}function l(e){var t,r,u;if(e.isSimple){t=new a(e.value,e.writable,e.validators,e.getter,e.setter,e.cast,null)}else if(e.isReference){var l=e.type.def;if(l.isSimple){t=new a(l.value,l.writable,l.validators,e.getter,e.setter,l.cast,null)}else{u=function(e){var t=false;if(n.isNullOrUndefined(e)){t=true}else{t=l===e.__def}if(!t){throw new Error("Value should be an instance of the referenced model, null or undefined")}};t=new a(e.value,e.writable,e.validators,e.getter,e.setter,null,u)}}else if(e.isArray){r=function(t){var r=i(e);Object.defineProperties(r,o(e,t));s(r);return r};u=function(e){if(!n.isArray(e)){throw new Error("Value should be an array")}};t=new a(r,e.writable,e.validators,e.getter,e.setter,null,u)}else{var c=i(e);r=function(t){var r=Object.create(c,o(e,t));s(r);return r};u=function(e){if(!c.isPrototypeOf(e)){throw new Error("Invalid prototype")}};t=new a(r,e.writable,e.validators,e.getter,e.setter,null,u)}var f=function(e){var r=Object.create(t);r.initialize(e);return r};f.wrapper=t;return f}t.exports=l},{"./proto":20,"./util":23,"./wrapper":25}],18:[function(e,t,r){"use strict";function n(e,t){var r=e.__def.isArray;var i=e.__def.defs;var a,o,s,u,l,c,f;if(i){a=Object.keys(i);for(u=0;u<a.length;u++){s=a[u];if(t.hasOwnProperty(s)){o=i[s];l=o.isSimple;c=o.isReference&&o.type.def.isSimple;f=o.isReference&&t[s]&&t[s].__supermodel;if(l||c||f){e[s]=t[s]}else if(t[s]){if(o.isReference){e[s]=o.type()}n(e[s],t[s])}}}}if(r&&Array.isArray(t)){for(u=0;u<t.length;u++){var p=e.create();e.push(p&&p.__supermodel?n(p,t[u]):t[u])}}return e}t.exports=n},{}],19:[function(e,t,r){"use strict";var n=e("./emitter-event");var i=e("./validation-error");var a=e("./wrapper");var o=e("./merge");var s={__supermodel:{value:true},__keys:{get:function(){var e=Object.keys(this);if(Array.isArray(this)){var t=["addEventListener","on","once","removeEventListener","removeAllListeners","removeListener","off","emit","listeners","hasListeners","pop","push","reverse","shift","sort","splice","update","unshift","create","__merge","__setNotifyChange","__notifyChange","__set","__get","__chain","__relativePath"];e=e.filter(function(e){return t.indexOf(e)<0})}return e}},__name:{get:function(){if(this.__isRoot){return""}var e=this.__parent.__keys;var t,r;for(var n=0;n<e.length;n++){t=e[n];r=this.__parent[t];if(r===this){return t}}}},__path:{get:function(){if(this.__hasAncestors&&!this.__parent.__isRoot){return this.__parent.__path+"."+this.__name}else{return this.__name}}},__isRoot:{get:function(){return!this.__hasAncestors}},__children:{get:function(){var e=[];var t=this.__keys;var r,n;for(var i=0;i<t.length;i++){r=t[i];n=this[r];if(n&&n.__supermodel){e.push(n)}}return e}},__ancestors:{get:function(){var e=[];var t=this;while(t.__parent){e.push(t.__parent);t=t.__parent}return e}},__descendants:{get:function(){var e=[];function t(r){var n=r.__keys;var i,a;for(var o=0;o<n.length;o++){i=n[o];a=r[i];if(a&&a.__supermodel){e.push(a);t(a)}}}t(this);return e}},__hasAncestors:{get:function(){return!!this.__ancestors.length}},__hasDescendants:{get:function(){return!!this.__descendants.length}},errors:{get:function(){var e=[];var t=this.__def;var r,n,o,s;var u=t.validators.slice(0);for(o=0;o<u.length;o++){r=u[o];n=r.call(this,this);if(n){e.push(new i(this,n,r))}}var l=this.__keys;var c,f,p;for(o=0;o<l.length;o++){f=l[o];if(t.isArray&&t.def&&(!t.defs||!(f in t.defs))){p=t.def;if(p.isSimple){c=p.create.wrapper;c.setValue(this[f])}else if(p.isReference&&p.type.def.isSimple){c=p.type.def.create.wrapper;c.setValue(this[f])}else{c=this[f]}}else{c=this.__[f]}if(c){if(c.__supermodel){Array.prototype.push.apply(e,c.errors)}else if(c instanceof a){var d=c.getValue(this);if(d&&d.__supermodel){Array.prototype.push.apply(e,d.errors)}else{var v=c.validators;for(s=0;s<v.length;s++){r=v[s];n=r.call(this,d,f);if(n){e.push(new i(this,n,r,f))}}}}}}return e}}};var u={__get:function(e){return this.__[e].getValue(this)},__set:function(e,t){this.__[e].setValue(t,this)},__relativePath:function(e,t){var r=this.__path?e.substr(this.__path.length+1):e;if(r){return t?r+"."+t:r}return t},__chain:function(e){return[this].concat(this.__ancestors).forEach(e)},__merge:function(e){return o(this,e)},__notifyChange:function(e,t,r){var i=this;var a=this.__path;var o="set";var s={oldValue:r,newValue:t};this.emit(o,new n(o,e,i,s));this.emit("change",new n(o,e,i,s));this.emit("change:"+e,new n(o,e,i,s));this.__ancestors.forEach(function(t){var r=t.__relativePath(a,e);t.emit("change",new n(o,r,i,s))})},__setNotifyChange:function(e,t){var r=this.__get(e);this.__set(e,t);var n=this.__get(e);this.__notifyChange(e,n,r)}};t.exports={proto:u,descriptors:s}},{"./emitter-event":15,"./merge":18,"./validation-error":24,"./wrapper":25}],20:[function(e,t,r){"use strict";var n=e("./emitter-object");var i=e("./emitter-array");var a=e("./emitter-event");var o=e("./util").extend;var s=e("./model");var u=s.proto;var l=s.descriptors;var c=Object.create(u,l);var f=function(){var e=Object.create(c);n(e);return e}();function p(){var e=i(function(e,t,r){if(e==="update"){t.__notifyChange(r.index,r.value,r.oldValue)}else{var n=t;var i=t.__path;var o=r;var s=r.index;t.emit(e,new a(e,"",n,o));t.emit("change",new a(e,"",n,o));t.__ancestors.forEach(function(t){var r=t.__relativePath(i,s);t.emit("change",new a(e,r,n,o))})}});Object.defineProperties(e,l);n(e);o(e,u);return e}function d(e){var t=Object.create(f);if(e){o(t,e)}return t}function v(e,t){var r=p();if(e){o(r,e)}if(t){var n=t.create.wrapper;h(r,n);r.create=function(){return t.isReference?t.type():t.create().getValue(this)}}return r}function h(e,t){function r(r){var n=[];for(var i=0;i<r.length;i++){t.setValue(r[i],e);n.push(t.getValue(e))}return n}var n=e.push;var i=e.unshift;var a=e.splice;var o=e.update;if(n){e.push=function(){var t=r(arguments);return n.apply(e,t)}}if(i){e.unshift=function(){var t=r(arguments);return i.apply(e,t)}}if(a){e.splice=function(){var t=r(Array.prototype.slice.call(arguments,2));t.unshift(arguments[1]);t.unshift(arguments[0]);return a.apply(e,t)}}if(o){e.update=function(){var t=r([arguments[1]]);t.unshift(arguments[0]);return o.apply(e,t)}}}function m(e){return e.isArray?v(e.proto,e.def):d(e.proto)}t.exports=m},{"./emitter-array":14,"./emitter-event":15,"./emitter-object":16,"./model":19,"./util":23}],21:[function(e,t,r){"use strict";t.exports={}},{}],22:[function(e,t,r){"use strict";var n=e("./def");var i=e("./supermodel");function a(e,t){var r=n(e);function a(e){var n=r.isSimple?r.create():r.create().getValue({});if(t){t.apply(n,arguments)}else if(e){n.__merge(e)}return n}Object.defineProperty(a,"def",{value:r});a.prototype=i;a.constructor=a;return a}t.exports=a},{"./def":13,"./supermodel":21}],23:[function(e,t,r){"use strict";var n=e("./supermodel");function i(e,t){if(!t||typeof t!=="object"){return e}var r=Object.keys(t);var n=r.length;while(n--){e[r[n]]=t[r[n]]}return e}var a={extend:i,typeOf:function(e){return Object.prototype.toString.call(e).match(/\s([a-zA-Z]+)/)[1].toLowerCase()},isObject:function(e){return this.typeOf(e)==="object"},isArray:function(e){return Array.isArray(e)},isSimple:function(e){return!this.isObject(e)&&!this.isArray(e)},isFunction:function(e){return this.typeOf(e)==="function"},isDate:function(e){return this.typeOf(e)==="date"},isNull:function(e){return e===null},isUndefined:function(e){return typeof e==="undefined"},isNullOrUndefined:function(e){return this.isNull(e)||this.isUndefined(e)},cast:function(e,t){if(!t){return e}switch(t){case String:return a.castString(e);case Number:return a.castNumber(e);case Boolean:return a.castBoolean(e);case Date:return a.castDate(e);case Object:case Function:return e;default:throw new Error("Invalid cast")}},castString:function(e){if(e===undefined||e===null||a.typeOf(e)==="string"){return e}return e.toString&&e.toString()},castNumber:function(e){if(e===undefined||e===null){return NaN}if(a.typeOf(e)==="number"){return e}return Number(e)},castBoolean:function(e){if(!e){return false}var t=["0","false","off","no"];return t.indexOf(e)===-1},castDate:function(e){if(e===undefined||e===null||a.typeOf(e)==="date"){return e}return new Date(e)},isConstructor:function(e){return this.isSimpleConstructor(e)||[Array,Object].indexOf(e)>-1},isSimpleConstructor:function(e){return[String,Number,Date,Boolean].indexOf(e)>-1},isSupermodelConstructor:function(e){return this.isFunction(e)&&e.prototype===n}};t.exports=a},{"./supermodel":21}],24:[function(e,t,r){"use strict";function n(e,t,r,n){this.target=e;this.error=t;this.validator=r;if(n){this.key=n}}t.exports=n},{}],25:[function(e,t,r){"use strict";var n=e("./util");function i(e,t,r,i,a,o,s){this.validators=r;this._defaultValue=e;this._writable=t;this._getter=i;this._setter=a;this._beforeSet=o;this._assert=s;this.isInitialized=false;if(!n.isFunction(e)){this.isInitialized=true;if(!n.isUndefined(e)){this._value=e}}}i.prototype.initialize=function(e){if(this.isInitialized){return}this.setValue(this._defaultValue(e),e);this.isInitialized=true};i.prototype.getValue=function(e){return this._getter?this._getter.call(e):this._value};i.prototype.setValue=function(e,t){if(!this._writable){throw new Error("Value is readonly")}if(e&&e.__supermodel&&t){if(e.__parent!==t){e.__parent=t}}var r;if(this._setter){this._setter.call(t,e);r=this.getValue(t)}else{r=this._beforeSet?this._beforeSet(e):e}if(this._assert){this._assert(r)}this._value=r};t.exports=i},{"./util":23}]},{},[9]);