Merge remote-tracking branch 'origin/rewrite' into rewrite

This commit is contained in:
Leo Horie 2016-12-02 17:42:50 -05:00
commit d56c30cc4a
4 changed files with 45 additions and 20 deletions

View file

@ -34,6 +34,6 @@ There are over 4000 assertions in the test suite, and tests cover even difficult
## Modularity
Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at <!-- size -->7.41 KB<!-- /size --> min+gzip
Despite the huge improvements in performance and modularity, the new codebase is smaller than v0.2.x, currently clocking at <!-- size -->7.42 KB<!-- /size --> min+gzip
In addition, Mithril is now completely modular: you can import only the modules that you need and easily integrate 3rd party modules if you wish to use a different library for routing, ajax, and even rendering

View file

@ -17,15 +17,17 @@
- [Accessing route params](#accessing-route-params)
- [Preventing unmounting](#preventing-unmounting)
- [`m.request`](#mrequest)
- [`m.sync` removed](#msync-removed)
- [`xlink` namespace required](#xlink-namespace-required)
- [Nested arrays in views](#nested-arrays-in-views)
- [`vnode` equality checks](#vnode-equality-checks)
- [Synchronous redraw removed](#synchronous-redraw-removed)
---
## `m.prop` removed
In `v1.x`, `m.prop` is now a more powerful stream micro-library, but it's no longer part of core.
In `v1.x`, `m.prop()` is now a more powerful stream micro-library, but it's no longer part of core.
### `v0.2.x`
@ -475,7 +477,13 @@ setTimeout(function() {
}, 1000)
```
The equivalent of `m.sync` is now `Promise.all`
Additionally, if the `extract` option is passed to `m.request` the return value of the provided function will be used directly to resolve its promise, and the `deserialize` callback is ignored.
---
## `m.sync` removed
`m.sync` has been removed in favor of `Promise.all`
### `v0.2.x`
@ -501,8 +509,6 @@ Promise.all([
})
```
Additionally, if the `extract` option is passed to `m.request` the return value of the provided function will be used directly to resolve its promise, and the `deserialize` callback is ignored.
---
## `xlink` namespace required
@ -538,3 +544,21 @@ Arrays now represent [fragments](fragment.md), which are structurally significan
## `vnode` equality checks
If a vnode is strictly equal to the vnode occupying its place in the last draw, v1.x will skip that part of the tree without checking for mutations or triggering any lifecycle methods in the subtree. The component documentation contains [more detail on this issue](components.md#avoid-creating-component-instances-outside-views).
---
## Synchronous redraw removed
In v0.2.x it was possible to force mithril to redraw immediately by passing a truthy value to `m.redraw()`. This behavior complicated usage of `m.redraw()` and caused some hard-to-reason about issues and has been removed.
### `v0.2.x`
```javascript
m.redraw(true); // redraws immediately & synchronously
```
### `v1.x`
```javascript
m.redraw(); // schedules a redraw on the next requestAnimationFrame tick
```

View file

@ -1117,7 +1117,8 @@ m.withAttr = function(attrName, callback1, context) {
return callback1.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName))
}
}
m.render = redrawService.render
var _27 = coreRenderer(window)
m.render = _27.render
m.redraw = redrawService.redraw
m.request = requestService.request
m.jsonp = requestService.jsonp

28
mithril.min.js vendored
View file

@ -1,20 +1,20 @@
new function(){function n(a,h,l,b,f,k){return{tag:a,key:h,attrs:l,children:b,text:f,dom:k,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function A(a){if(null==a||"string"!==typeof a&&null==a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a&&void 0===I[a]){for(var h,l,b=[],f={};h=N.exec(a);){var k=h[1],v=h[2];""===k&&""!==v?l=v:"#"===k?f.id=v:"."===k?b.push(v):"["===h[3][0]&&((k=h[6])&&(k=k.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
new function(){function n(a,h,l,b,f,k){return{tag:a,key:h,attrs:l,children:b,text:f,dom:k,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function A(a){if(null==a||"string"!==typeof a&&null==a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a&&void 0===I[a]){for(var h,l,b=[],f={};h=O.exec(a);){var k=h[1],v=h[2];""===k&&""!==v?l=v:"#"===k?f.id=v:"."===k?b.push(v):"["===h[3][0]&&((k=h[6])&&(k=k.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
"class"===h[4]?b.push(k):f[h[4]]=k||!0)}0<b.length&&(f.className=b.join(" "));I[a]=function(a,b){var k=!1,h,d,w=a.className||a["class"],u;for(u in f)a[u]=f[u];void 0!==w&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=w),void 0!==f.className&&(a.className=f.className+" "+w));for(u in a)if("key"!==u){k=!0;break}b instanceof Array&&1==b.length&&null!=b[0]&&"#"===b[0].tag?d=b[0].children:h=b;return n(l||"div",a.key,k?a:void 0,h,d,void 0)}}var p;null!=arguments[1]&&("object"!==typeof arguments[1]||
void 0!==arguments[1].tag||arguments[1]instanceof Array)?b=1:(p=arguments[1],b=2);if(arguments.length===b+1)h=arguments[b]instanceof Array?arguments[b]:[arguments[b]];else for(h=[];b<arguments.length;b++)h.push(arguments[b]);return"string"===typeof a?I[a](p||{},n.normalizeChildren(h)):n(a,p&&p.key,p||{},n.normalizeChildren(h),void 0,void 0)}n.normalize=function(a){return a instanceof Array?n("[",void 0,void 0,n.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?n("#",void 0,void 0,a,
void 0,void 0):a};n.normalizeChildren=function(a){for(var h=0;h<a.length;h++)a[h]=n.normalize(a[h]);return a};var N=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,I={};A.trust=function(a){null==a&&(a="");return n("<",void 0,void 0,a,void 0,void 0)};A.fragment=function(a,h){return n("[",a.key,a,n.normalizeChildren(h),void 0,void 0)};var t=function(a){function h(a,h){return function w(u){var r;try{if(!h||null==u||"object"!==typeof u&&"function"!==typeof u||"function"!==
void 0,void 0):a};n.normalizeChildren=function(a){for(var h=0;h<a.length;h++)a[h]=n.normalize(a[h]);return a};var O=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,I={};A.trust=function(a){null==a&&(a="");return n("<",void 0,void 0,a,void 0,void 0)};A.fragment=function(a,h){return n("[",a.key,a,n.normalizeChildren(h),void 0,void 0)};var t=function(a){function h(a,h){return function w(u){var r;try{if(!h||null==u||"object"!==typeof u&&"function"!==typeof u||"function"!==
typeof(r=u.then))C(function(){h||0!==a.length||console.error("Possible unhandled promise rejection:",u);for(var b=0;b<a.length;b++)a[b](u);f.length=0;k.length=0;q.state=h;q.retry=function(){w(u)}});else{if(u===b)throw new TypeError("Promise can't be resolved w/ itself");l(r.bind(u))}}catch(F){p(F)}}}function l(a){function b(a){return function(b){0<d++||a(b)}}var d=0,f=b(p);try{a(b(v),f)}catch(u){f(u)}}if(!(this instanceof t))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");
var b=this,f=[],k=[],v=h(f,!0),p=h(k,!1),q=b._instance={resolvers:f,rejectors:k},C="function"===typeof setImmediate?setImmediate:setTimeout;l(a)};t.prototype.then=function(a,h){function l(a,h,l,r){h.push(function(b){if("function"!==typeof a)l(b);else try{f(a(b))}catch(d){k&&k(d)}});"function"===typeof b.retry&&r===b.state&&b.retry()}var b=this._instance,f,k,v=new t(function(a,b){f=a;k=b});l(a,b.resolvers,f,!0);l(h,b.rejectors,k,!1);return v};t.prototype["catch"]=function(a){return this.then(null,
a)};t.resolve=function(a){return a instanceof t?a:new t(function(h){h(a)})};t.reject=function(a){return new t(function(h,l){l(a)})};t.all=function(a){return new t(function(h,l){var b=a.length,f=0,k=[];if(0===a.length)h([]);else for(var v=0;v<a.length;v++)(function(v){function q(a){f++;k[v]=a;f===b&&h(k)}null==a[v]||"object"!==typeof a[v]&&"function"!==typeof a[v]||"function"!==typeof a[v].then?q(a[v]):a[v].then(q,l)})(v)})};t.race=function(a){return new t(function(h,l){for(var b=0;b<a.length;b++)a[b].then(h,
l)})};"undefined"===typeof Promise&&("undefined"!==typeof window?window.Promise=t:"undefined"!==typeof global&&(global.Promise=t));var G=function(a){function h(a,b){if(b instanceof Array)for(var f=0;f<b.length;f++)h(a+"["+f+"]",b[f]);else if("[object Object]"===Object.prototype.toString.call(b))for(f in b)h(a+"["+f+"]",b[f]);else l.push(encodeURIComponent(a)+(null!=b&&""!==b?"="+encodeURIComponent(b):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var l=[],b;for(b in a)h(b,
a[b]);return l.join("&")},J=function(a,h){function l(){0===--r&&"function"===typeof m&&m()}function b(a){var d=a.then;a.then=function(){r++;var f=d.apply(a,arguments);f.then(l,function(a){l();throw a;});return b(f)};return a}function f(a,b){if(null==b)return a;for(var d=a.match(/:[^\/]+/gi)||[],f=0;f<d.length;f++){var h=d[f].slice(1);null!=b[h]&&(a=a.replace(d[f],b[h]),delete b[h])}return a}function k(a,b){var d=G(b);if(""!==d){var f=0>a.indexOf("?")?"?":"&";a+=f+d}return a}function v(a){try{return""!==
l)})};"undefined"===typeof Promise&&("undefined"!==typeof window?window.Promise=t:"undefined"!==typeof global&&(global.Promise=t));var E=function(a){function h(a,b){if(b instanceof Array)for(var f=0;f<b.length;f++)h(a+"["+f+"]",b[f]);else if("[object Object]"===Object.prototype.toString.call(b))for(f in b)h(a+"["+f+"]",b[f]);else l.push(encodeURIComponent(a)+(null!=b&&""!==b?"="+encodeURIComponent(b):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var l=[],b;for(b in a)h(b,
a[b]);return l.join("&")},J=function(a,h){function l(){0===--r&&"function"===typeof m&&m()}function b(a){var d=a.then;a.then=function(){r++;var f=d.apply(a,arguments);f.then(l,function(a){l();throw a;});return b(f)};return a}function f(a,b){if(null==b)return a;for(var d=a.match(/:[^\/]+/gi)||[],f=0;f<d.length;f++){var h=d[f].slice(1);null!=b[h]&&(a=a.replace(d[f],b[h]),delete b[h])}return a}function k(a,b){var d=E(b);if(""!==d){var f=0>a.indexOf("?")?"?":"&";a+=f+d}return a}function v(a){try{return""!==
a?JSON.parse(a):null}catch(w){throw Error(a);}}function p(a){return a.responseText}function q(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;d<b.length;d++)b[d]=new a(b[d]);else return new a(b);return b}var n=0,r=0,m;return{request:function(d,l){return b(new h(function(b,h){if("string"===typeof d){var r=d;d=l||{};null==d.url&&(d.url=r)}null==d.method&&(d.method="GET");d.method=d.method.toUpperCase();r="boolean"===typeof d.useBody?d.useBody:"GET"!==d.method&&"TRACE"!==d.method;"function"!==
typeof d.serialize&&(d.serialize="undefined"!==typeof FormData&&d.data instanceof FormData?function(a){return a}:JSON.stringify);"function"!==typeof d.deserialize&&(d.deserialize=v);"function"!==typeof d.extract&&(d.extract=p);d.url=f(d.url,d.data);r?d.data=d.serialize(d.data):d.url=k(d.url,d.data);var m=new a.XMLHttpRequest;m.open(d.method,d.url,"boolean"===typeof d.async?d.async:!0,"string"===typeof d.user?d.user:void 0,"string"===typeof d.password?d.password:void 0);d.serialize===JSON.stringify&&
r&&m.setRequestHeader("Content-Type","application/json; charset=utf-8");d.deserialize===v&&m.setRequestHeader("Accept","application/json, text/*");d.withCredentials&&(m.withCredentials=d.withCredentials);"function"===typeof d.config&&(m=d.config(m,d)||m);m.onreadystatechange=function(){if(4===m.readyState)try{var a=d.extract!==p?d.extract(m,d):d.deserialize(d.extract(m,d));if(200<=m.status&&300>m.status||304===m.status)b(q(d.type,a));else{var f=Error(m.responseText),k;for(k in a)f[k]=a[k];h(f)}}catch(H){h(H)}};
r&&m.setRequestHeader("Content-Type","application/json; charset=utf-8");d.deserialize===v&&m.setRequestHeader("Accept","application/json, text/*");d.withCredentials&&(m.withCredentials=d.withCredentials);"function"===typeof d.config&&(m=d.config(m,d)||m);m.onreadystatechange=function(){if(4===m.readyState)try{var a=d.extract!==p?d.extract(m,d):d.deserialize(d.extract(m,d));if(200<=m.status&&300>m.status||304===m.status)b(q(d.type,a));else{var f=Error(m.responseText),k;for(k in a)f[k]=a[k];h(f)}}catch(G){h(G)}};
r&&null!=d.data?m.send(d.data):m.send()}))},jsonp:function(d){return b(new h(function(b,h){var m=d.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+n++,r=a.document.createElement("script");a[m]=function(f){r.parentNode.removeChild(r);b(q(d.type,f));delete a[m]};r.onerror=function(){r.parentNode.removeChild(r);h(Error("JSONP request failed"));delete a[m]};null==d.data&&(d.data={});d.url=f(d.url,d.data);d.data[d.callbackKey||"callback"]=m;r.src=k(d.url,d.data);a.document.documentElement.appendChild(r)}))},
setCompletionCallback:function(a){m=a}}}(window,"undefined"!==typeof Promise?Promise:t),O=function(a){function h(g,c,a,b,d,f,h){for(;a<b;a++){var e=c[a];null!=e&&q(g,l(e,d,h),f)}}function l(g,c,a){var e=g.tag;null!=g.attrs&&t(g.attrs,g,c);if("string"===typeof e)switch(e){case "#":return g.dom=B.createTextNode(g.children);case "<":return b(g);case "[":var d=B.createDocumentFragment();null!=g.children&&(e=g.children,h(d,e,0,e.length,c,null,a));g.dom=d.firstChild;g.domSize=d.childNodes.length;return d;
setCompletionCallback:function(a){m=a}}}(window,"undefined"!==typeof Promise?Promise:t),N=function(a){function h(g,c,a,b,d,f,h){for(;a<b;a++){var e=c[a];null!=e&&q(g,l(e,d,h),f)}}function l(g,c,a){var e=g.tag;null!=g.attrs&&t(g.attrs,g,c);if("string"===typeof e)switch(e){case "#":return g.dom=B.createTextNode(g.children);case "<":return b(g);case "[":var d=B.createDocumentFragment();null!=g.children&&(e=g.children,h(d,e,0,e.length,c,null,a));g.dom=d.firstChild;g.domSize=d.childNodes.length;return d;
default:var f=g.tag;switch(g.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}var m=(e=g.attrs)&&e.is,f=a?m?B.createElementNS(a,f,{is:m}):B.createElementNS(a,f):m?B.createElement(f,{is:m}):B.createElement(f);g.dom=f;if(null!=e)for(d in m=a,e)u(g,d,null,e[d],m);null!=g.attrs&&null!=g.attrs.contenteditable?C(g):(null!=g.text&&(""!==g.text?f.textContent=g.text:g.children=[n("#",void 0,void 0,g.text,void 0,void 0)]),null!=g.children&&(d=g.children,
h(f,d,0,d.length,c,null,a),c=g.attrs,"select"===g.tag&&null!=c&&("value"in c&&u(g,"value",null,c.value,void 0),"selectedIndex"in c&&u(g,"selectedIndex",null,c.selectedIndex,void 0))));return f}else{g.state||(g.state={});E(g.state,g.tag);d=g.tag.view;if(null!=d.reentrantLock)g=H;else if(d.reentrantLock=!0,t(g.tag,g,c),g.instance=n.normalize(d.call(g.state,g)),d.reentrantLock=null,null!=g.instance){if(g.instance===g)throw Error("A view cannot return the vnode it received as arguments");c=l(g.instance,
c,a);g.dom=g.instance.dom;g.domSize=null!=g.dom?g.instance.domSize:0;g=c}else g.domSize=0,g=H;return g}}function b(g){var c={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(g.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",c=B.createElement(c);c.innerHTML=g.children;g.dom=c.firstChild;g.domSize=c.childNodes.length;g=B.createDocumentFragment();for(var a;a=c.firstChild;)g.appendChild(a);return g}function f(g,c,a,d,b,f){if(c!==a&&
h(f,d,0,d.length,c,null,a),c=g.attrs,"select"===g.tag&&null!=c&&("value"in c&&u(g,"value",null,c.value,void 0),"selectedIndex"in c&&u(g,"selectedIndex",null,c.selectedIndex,void 0))));return f}else{g.state||(g.state={});E(g.state,g.tag);d=g.tag.view;if(null!=d.reentrantLock)g=G;else if(d.reentrantLock=!0,t(g.tag,g,c),g.instance=n.normalize(d.call(g.state,g)),d.reentrantLock=null,null!=g.instance){if(g.instance===g)throw Error("A view cannot return the vnode it received as arguments");c=l(g.instance,
c,a);g.dom=g.instance.dom;g.domSize=null!=g.dom?g.instance.domSize:0;g=c}else g.domSize=0,g=G;return g}}function b(g){var c={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(g.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",c=B.createElement(c);c.innerHTML=g.children;g.dom=c.firstChild;g.domSize=c.childNodes.length;g=B.createDocumentFragment();for(var a;a=c.firstChild;)g.appendChild(a);return g}function f(g,c,a,d,b,f){if(c!==a&&
(null!=c||null!=a))if(null==c)h(g,a,0,a.length,d,b,void 0);else if(null==a)r(c,0,c.length,a);else if(c.length===a.length&&null!=a[0]&&null==a[0].key)for(var e=0;e<c.length;e++)c[e]===a[e]||null==c[e]&&null==a[e]||(null==c[e]?q(g,l(a[e],d,f),p(c,e+1,b)):null==a[e]?r(c,e,e+1,a):k(g,c[e],a[e],d,p(c,e+1,b),!1,f));else{a:{if(null!=c.pool&&Math.abs(c.pool.length-a.length)<=Math.abs(c.length-a.length)&&(e=a[0]&&a[0].children&&a[0].children.length||0,Math.abs((c.pool[0]&&c.pool[0].children&&c.pool[0].children.length||
0)-e)<=Math.abs((c[0]&&c[0].children&&c[0].children.length||0)-e))){e=!0;break a}e=!1}e&&(c=c.concat(c.pool));for(var m=0,y=0,z=c.length-1,u=a.length-1,w;z>=m&&u>=y;){var x=c[m],n=a[y];if(x!==n||e)if(null==x)m++;else if(null==n)y++;else if(x.key===n.key)m++,y++,k(g,x,n,d,p(c,m,b),e,f),e&&x.tag===n.tag&&q(g,v(x),b);else if(x=c[z],x!==n||e)if(null==x)z--;else if(null==n)y++;else if(x.key===n.key)k(g,x,n,d,p(c,z+1,b),e,f),(e||y<u)&&q(g,v(x),p(c,m,b)),z--,y++;else break;else z--,y++;else m++,y++}for(;z>=
m&&u>=y;){x=c[z];n=a[u];if(x!==n||e)if(null==x)z--;else{if(null!=n)if(x.key===n.key)k(g,x,n,d,p(c,z+1,b),e,f),e&&x.tag===n.tag&&q(g,v(x),b),null!=x.dom&&(b=x.dom),z--;else{if(!w){w=c;var x=z,D={},t;for(t=0;t<x;t++){var C=w[t];null!=C&&(C=C.key,null!=C&&(D[C]=t))}w=D}null!=n&&(x=w[n.key],null!=x?(D=c[x],k(g,D,n,d,p(c,z+1,b),e,f),q(g,v(D),b),c[x].skip=!0,null!=D.dom&&(b=D.dom)):(n=l(n,d,void 0),q(g,n,b),b=n))}u--}else z--,u--;if(u<y)break}h(g,a,y,u+1,d,b,f);r(c,m,z+1,a)}}function k(a,c,e,h,m,r,w){var g=
@ -28,13 +28,13 @@ g.onupdate||g.onbeforeremove||g.onremove));g&&"string"===typeof a.tag&&(c.pool?c
a instanceof Array)for(var c=0;c<a.length;c++){var g=a[c];null!=g&&w(g)}}function u(a,c,e,b,d){var g=a.dom;if("key"!==c&&(e!==b||"value"===c||"checked"===c||"selectedIndex"===c||"selected"===c&&a.dom===B.activeElement||"object"===typeof b)&&"undefined"!==typeof b&&!M(c)){var f=c.indexOf(":");if(-1<f&&"xlink"===c.substr(0,f))g.setAttributeNS("http://www.w3.org/1999/xlink",c.slice(f+1),b);else if("o"===c[0]&&"n"===c[1]&&"function"===typeof b)F(a,c,b);else if("style"===c)if(a=e,a===b&&(g.style.cssText=
"",a=null),null==b)g.style.cssText="";else if("string"===typeof b)g.style.cssText=b;else{"string"===typeof a&&(g.style.cssText="");for(var h in b)g.style[h]=b[h];if(null!=a&&"string"!==typeof a)for(h in a)h in b||(g.style[h]="")}else c in g&&"href"!==c&&"list"!==c&&"form"!==c&&"width"!==c&&"height"!==c&&void 0===d?"input"===a.tag&&"value"===c&&a.dom.value===b&&a.dom===B.activeElement||"select"===a.tag&&"value"===c&&a.dom.value===b&&a.dom===B.activeElement||"option"===a.tag&&"value"===c&&a.dom.value===
b||(g[c]=b):"boolean"===typeof b?b?g.setAttribute(c,""):g.removeAttribute(c):g.setAttribute("className"===c?"class":c,b)}}function M(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function F(a,c,b){var e=a.dom,g=function(a){var c=b.call(e,a);"function"===typeof K&&K.call(e,a);return c};if(c in e)e[c]="function"===typeof b?g:null;else{var d=c.slice(2);void 0===a.events&&(a.events={});null!=a.events[c]&&e.removeEventListener(d,a.events[c],
!1);"function"===typeof b&&(a.events[c]=g,e.addEventListener(d,a.events[c],!1))}}function t(a,c,b){"function"===typeof a.oninit&&a.oninit.call(c.state,c);"function"===typeof a.oncreate&&b.push(a.oncreate.bind(c.state,c))}function A(a,c,b,d){d?t(a,c,b):"function"===typeof a.onupdate&&b.push(a.onupdate.bind(c.state,c))}function E(a,c){Object.keys(c).forEach(function(b){a[b]=c[b]})}var B=a.document,H=B.createDocumentFragment(),K;return{render:function(a,c){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");
var b=[],d=B.activeElement;null==a.vnodes&&(a.textContent="");c instanceof Array||(c=[c]);f(a,a.vnodes,n.normalizeChildren(c),b,null,void 0);a.vnodes=c;for(var g=0;g<b.length;g++)b[g]();B.activeElement!==d&&d.focus()},setEventCallback:function(a){return K=a}}},E=function(a){function h(a){a=b.indexOf(a);-1<a&&b.splice(a,2)}function l(){for(var a=1;a<b.length;a+=2)b[a]()}a=O(a);a.setEventCallback(function(a){!1!==a.redraw&&l()});var b=[];return{subscribe:function(a,k){h(a);b.push(a,k)},unsubscribe:h,
redraw:l,render:a.render}}(window);J.setCompletionCallback(E.redraw);A.mount=function(a){function h(a){var b=0,f=null,h="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var k=Date.now();0===b||16<=k-b?(b=k,a()):null===f&&(f=h(function(){f=null;a();b=Date.now()},16-(k-b)))}}return function(l,b){if(null===b)a.render(l,[]),a.unsubscribe(l);else{if(null==b.view)throw Error("m.mount(element, component) expects a component, not a vnode");var f=h(function(){a.render(l,
n(b))});a.subscribe(l,f);f()}}}(E);var L=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var h={},l={},b=0;b<a.length;b++){var f=a[b].split("="),k=decodeURIComponent(f[0]),f=2===f.length?decodeURIComponent(f[1]):"";"true"===f?f=!0:"false"===f&&(f=!1);var n=k.split(/\]\[?|\[/),p=h;-1<k.indexOf("[")&&n.pop();for(var q=0;q<n.length;q++){var k=n[q],t=n[q+1],t=""==t||!isNaN(parseInt(t,10)),r=q===n.length-1;""===k&&(k=n.slice(0,q).join(),null==l[k]&&(l[k]=0),
!1);"function"===typeof b&&(a.events[c]=g,e.addEventListener(d,a.events[c],!1))}}function t(a,c,b){"function"===typeof a.oninit&&a.oninit.call(c.state,c);"function"===typeof a.oncreate&&b.push(a.oncreate.bind(c.state,c))}function A(a,c,b,d){d?t(a,c,b):"function"===typeof a.onupdate&&b.push(a.onupdate.bind(c.state,c))}function E(a,c){Object.keys(c).forEach(function(b){a[b]=c[b]})}var B=a.document,G=B.createDocumentFragment(),K;return{render:function(a,c){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");
var b=[],d=B.activeElement;null==a.vnodes&&(a.textContent="");c instanceof Array||(c=[c]);f(a,a.vnodes,n.normalizeChildren(c),b,null,void 0);a.vnodes=c;for(var g=0;g<b.length;g++)b[g]();B.activeElement!==d&&d.focus()},setEventCallback:function(a){return K=a}}},H=function(a){function h(a){a=b.indexOf(a);-1<a&&b.splice(a,2)}function l(){for(var a=1;a<b.length;a+=2)b[a]()}a=N(a);a.setEventCallback(function(a){!1!==a.redraw&&l()});var b=[];return{subscribe:function(a,k){h(a);b.push(a,k)},unsubscribe:h,
redraw:l,render:a.render}}(window);J.setCompletionCallback(H.redraw);A.mount=function(a){function h(a){var b=0,f=null,h="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var k=Date.now();0===b||16<=k-b?(b=k,a()):null===f&&(f=h(function(){f=null;a();b=Date.now()},16-(k-b)))}}return function(l,b){if(null===b)a.render(l,[]),a.unsubscribe(l);else{if(null==b.view)throw Error("m.mount(element, component) expects a component, not a vnode");var f=h(function(){a.render(l,
n(b))});a.subscribe(l,f);f()}}}(H);var L=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var h={},l={},b=0;b<a.length;b++){var f=a[b].split("="),k=decodeURIComponent(f[0]),f=2===f.length?decodeURIComponent(f[1]):"";"true"===f?f=!0:"false"===f&&(f=!1);var n=k.split(/\]\[?|\[/),p=h;-1<k.indexOf("[")&&n.pop();for(var q=0;q<n.length;q++){var k=n[q],t=n[q+1],t=""==t||!isNaN(parseInt(t,10)),r=q===n.length-1;""===k&&(k=n.slice(0,q).join(),null==l[k]&&(l[k]=0),
k=l[k]++);null==p[k]&&(p[k]=r?f:t?[]:{});p=p[k]}}return h},P=function(a){function h(b){var f=a.location[b].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===b&&"/"!==f[0]&&(f="/"+f);return f}function l(a){return function(b){null==t&&(t=p(function(){t=null;a(b)}))}}function b(a,b,d){var f=a.indexOf("?"),h=a.indexOf("#"),m=-1<f?f:-1<h?h:a.length;if(-1<f){var f=L(a.slice(f+1,-1<h?h:a.length)),k;for(k in f)b[k]=f[k]}if(-1<h)for(k in b=L(a.slice(h+1)),b)d[k]=b[k];return a.slice(0,m)}
function f(){switch(q.charAt(0)){case "#":return h("hash").slice(q.length);case "?":return h("search").slice(q.length)+h("hash");default:return h("pathname").slice(q.length)+h("search")+h("hash")}}function k(f,h,d){var m={},k={};f=b(f,m,k);if(null!=h){for(var l in h)m[l]=h[l];f=f.replace(/:([^\/]+)/g,function(a,b){delete m[b];return h[b]})}(l=G(m))&&(f+="?"+l);(k=G(k))&&(f+="#"+k);n?(d&&d.replace?a.history.replaceState(null,null,q+f):a.history.pushState(null,null,q+f),a.onpopstate(!0)):a.location.href=
function f(){switch(q.charAt(0)){case "#":return h("hash").slice(q.length);case "?":return h("search").slice(q.length)+h("hash");default:return h("pathname").slice(q.length)+h("search")+h("hash")}}function k(f,h,d){var m={},k={};f=b(f,m,k);if(null!=h){for(var l in h)m[l]=h[l];f=f.replace(/:([^\/]+)/g,function(a,b){delete m[b];return h[b]})}(l=E(m))&&(f+="?"+l);(k=E(k))&&(f+="#"+k);n?(d&&d.replace?a.history.replaceState(null,null,q+f):a.history.pushState(null,null,q+f),a.onpopstate(!0)):a.location.href=
q+f}var n="function"===typeof a.history.pushState,p="function"===typeof setImmediate?setImmediate:setTimeout,q="#!",t;return{setPrefix:function(a){q=a},getPath:f,setPath:k,defineRoutes:function(h,m,d){function k(a){var k=f(),l={},n=b(k,l,l),r;for(r in h){var p=new RegExp("^"+r.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(p.test(n)){n.replace(p,function(){for(var b=r.match(/:[^\/]+/g)||[],d=[].slice.call(arguments,1,-2),f=0;f<b.length;f++)l[b[f].replace(/:|\./g,"")]=
decodeURIComponent(d[f]);m(h[r],l,k,r,!!a)});return}}d(k,l)}n?a.onpopstate=l(k):"#"===q.charAt(0)&&(a.onhashchange=k);k(!0);return function(){k(!1)}},link:function(a){a.dom.setAttribute("href",q+a.attrs.href);a.dom.onclick=function(a){a.ctrlKey||a.metaKey||a.shiftKey||2===a.which||(a.preventDefault(),a.redraw=!1,a=this.getAttribute("href"),0===a.indexOf(q)&&(a=a.slice(q.length)),k(a,void 0,void 0))}}}};A.route=function(a,h){var l=P(a),b=function(a){return a},f={render:b,component:null,path:null,resolve:null},
k=function(a,k,q){if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var p=function(k,m,d,l){f.render=k.render||b;f.component=m;f.path=l;f.resolve=null;h.render(a,f.render(n(m,void 0,d)))};q=l.defineRoutes(q,function(a,b,d,h,k){a.view?p({},a,b,d):a.onmatch?!1===k&&f.path===d||null!=f.resolve?p(f,f.component,b):(f.resolve=function(f){p(a,f,b,d)},a.onmatch(function(a){f.path!==d&&null!=f.resolve&&f.resolve(a)},b,d)):p(a,"div",b,d)},function(){l.setPath(k)});
h.subscribe(a,q)};k.set=l.setPath;k.get=function(){return f.path};k.prefix=l.setPrefix;k.link=l.link;return k}(window,E);A.withAttr=function(a,h,l){return function(b){return h.call(l||this,a in b.currentTarget?b.currentTarget[a]:b.currentTarget.getAttribute(a))}};A.render=E.render;A.redraw=E.redraw;A.request=J.request;A.jsonp=J.jsonp;A.parseQueryString=L;A.buildQueryString=G;A.version="1.0.0-rc.5";"undefined"!==typeof module?module.exports=A:window.m=A};
h.subscribe(a,q)};k.set=l.setPath;k.get=function(){return f.path};k.prefix=l.setPrefix;k.link=l.link;return k}(window,H);A.withAttr=function(a,h,l){return function(b){return h.call(l||this,a in b.currentTarget?b.currentTarget[a]:b.currentTarget.getAttribute(a))}};var Q=N(window);A.render=Q.render;A.redraw=H.redraw;A.request=J.request;A.jsonp=J.jsonp;A.parseQueryString=L;A.buildQueryString=E;A.version="1.0.0-rc.5";"undefined"!==typeof module?module.exports=A:window.m=A};