Merge remote-tracking branch 'origin/rewrite' into rewrite
This commit is contained in:
commit
2d1594714c
7 changed files with 112 additions and 50 deletions
|
|
@ -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.55 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.59 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
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ Argument | Type | Required | Descr
|
|||
`options.password` | `String` | No | A password for HTTP authorization. Defaults to `undefined`. This option is provided for `XMLHttpRequest` compatibility, but you should avoid using it because it sends the password in plain text over the network.
|
||||
`options.withCredentials` | `Boolean` | No | Whether to send cookies to 3rd party domains. Defaults to `false`
|
||||
`options.config` | `xhr = Function(xhr)` | No | Exposes the underlying XMLHttpRequest object for low-level configuration. Defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function).
|
||||
`options.headers` | `Object` | No | Headers to append to the request before sending it (applied right before `options.config`).
|
||||
`options.type` | `any = Function(any)` | No | A constructor to be applied to each object in the response. Defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function).
|
||||
`options.serialize` | `string = Function(any)` | No | A serialization method to be applied to `data`. Defaults to `JSON.stringify`, or if `options.data` is an instance of [`FormData`](https://developer.mozilla.org/en/docs/Web/API/FormData), defaults to the [identity function](https://en.wikipedia.org/wiki/Identity_function) (i.e. `function(value) {return value}`).
|
||||
`options.deserialize` | `any = Function(string)` | No | A deserialization method to be applied to the response. Defaults to a small wrapper around `JSON.parse` that returns `null` for empty responses.
|
||||
|
|
@ -404,7 +405,21 @@ function parseCSV(data) {
|
|||
}
|
||||
```
|
||||
|
||||
Ignoring the fact that the parseCSV function above doesn't handle a lot of cases that a proper CSV parser would, the code above logs an array of arrays
|
||||
Ignoring the fact that the parseCSV function above doesn't handle a lot of cases that a proper CSV parser would, the code above logs an array of arrays.
|
||||
|
||||
Custom headers may also be helpful in this regard. For example, if you're requesting an SVG, you probably want to set the content type accordingly. To override the default JSON request type, set `options.headers` to an object of key-value pairs corresponding to request header names and values.
|
||||
|
||||
```javascript
|
||||
m.request({
|
||||
method: "GET",
|
||||
url: "/files/image.svg",
|
||||
headers: {
|
||||
"Content-Type": "image/svg+xml; charset=utf-8",
|
||||
"Accept": "image/svg, text/*"
|
||||
},
|
||||
deserialize: function(value) {return value}
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -485,4 +500,3 @@ m.request("/api/v1/users").then(function(users) {
|
|||
console.log("list of users:", users)
|
||||
})
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -232,7 +232,6 @@ var _8 = function($window, Promise) {
|
|||
}
|
||||
return args
|
||||
}
|
||||
|
||||
function request(args, extra) {
|
||||
var finalize = finalizer()
|
||||
args = normalize(args, extra)
|
||||
|
|
@ -255,6 +254,9 @@ var _8 = function($window, Promise) {
|
|||
xhr.setRequestHeader("Accept", "application/json, text/*")
|
||||
}
|
||||
if (args.withCredentials) xhr.withCredentials = args.withCredentials
|
||||
for (var key in args.headers) if ({}.hasOwnProperty.call(args.headers, key)) {
|
||||
xhr.setRequestHeader(key, args.headers[key])
|
||||
}
|
||||
if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
|
|
@ -282,7 +284,6 @@ var _8 = function($window, Promise) {
|
|||
function jsonp(args, extra) {
|
||||
var finalize = finalizer()
|
||||
args = normalize(args, extra)
|
||||
|
||||
var promise0 = new Promise(function(resolve, reject) {
|
||||
var callbackName = args.callbackName || "_mithril_" + Math.round(Math.random() * 1e16) + "_" + callbackCount++
|
||||
var script = $window.document.createElement("script")
|
||||
|
|
|
|||
84
mithril.min.js
vendored
84
mithril.min.js
vendored
|
|
@ -1,42 +1,42 @@
|
|||
new function(){function w(a,c,g,d,f,l){return{tag:a,key:c,attrs:g,children:d,text:f,dom:l,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===G[a]){for(var c,g,d=[],f={};c=N.exec(a);){var l=c[1],k=c[2];""===l&&""!==k?g=k:"#"===l?f.id=k:"."===l?d.push(k):"["===c[3][0]&&((l=c[6])&&(l=l.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
|
||||
"class"===c[4]?d.push(l):f[c[4]]=l||!0)}0<d.length&&(f.className=d.join(" "));G[a]=function(a,c){var d=!1,b,l,q=a.className||a["class"],z;for(z in f)a[z]=f[z];void 0!==q&&(void 0!==a["class"]&&(a["class"]=void 0,a.className=q),void 0!==f.className&&(a.className=f.className+" "+q));for(z in a)if("key"!==z){d=!0;break}c instanceof Array&&1==c.length&&null!=c[0]&&"#"===c[0].tag?l=c[0].children:b=c;return w(g||"div",a.key,d?a:void 0,b,l,void 0)}}var r;null!=arguments[1]&&("object"!==typeof arguments[1]||
|
||||
void 0!==arguments[1].tag||arguments[1]instanceof Array)?d=1:(r=arguments[1],d=2);if(arguments.length===d+1)c=arguments[d]instanceof Array?arguments[d]:[arguments[d]];else for(c=[];d<arguments.length;d++)c.push(arguments[d]);return"string"===typeof a?G[a](r||{},w.normalizeChildren(c)):w(a,r&&r.key,r||{},w.normalizeChildren(c),void 0,void 0)}function O(a){var c=0,g=null,d="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var f=Date.now();0===c||16<=f-c?(c=
|
||||
f,a()):null===g&&(g=d(function(){g=null;a();c=Date.now()},16-(f-c)))}}w.normalize=function(a){return a instanceof Array?w("[",void 0,void 0,w.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?w("#",void 0,void 0,a,void 0,void 0):a};w.normalizeChildren=function(a){for(var c=0;c<a.length;c++)a[c]=w.normalize(a[c]);return a};var N=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,G={};A.trust=function(a){null==a&&(a="");return w("<",void 0,void 0,a,void 0,
|
||||
void 0)};A.fragment=function(a,c){return w("[",a.key,a,w.normalizeChildren(c),void 0,void 0)};var x=function(a){function c(a,b){return function n(c){var k;try{if(!b||null==c||"object"!==typeof c&&"function"!==typeof c||"function"!==typeof(k=c.then))m(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",c);for(var d=0;d<a.length;d++)a[d](c);f.length=0;l.length=0;q.state=b;q.retry=function(){n(c)}});else{if(c===d)throw new TypeError("Promise can't be resolved w/ itself");
|
||||
g(k.bind(c))}}catch(P){r(P)}}}function g(a){function b(b){return function(a){0<c++||b(a)}}var c=0,d=b(r);try{a(b(k),d)}catch(z){d(z)}}if(!(this instanceof x))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");var d=this,f=[],l=[],k=c(f,!0),r=c(l,!1),q=d._instance={resolvers:f,rejectors:l},m="function"===typeof setImmediate?setImmediate:setTimeout;g(a)};x.prototype.then=function(a,c){function g(a,c,g,k){c.push(function(b){if("function"!==
|
||||
typeof a)g(b);else try{f(a(b))}catch(C){l&&l(C)}});"function"===typeof d.retry&&k===d.state&&d.retry()}var d=this._instance,f,l,k=new x(function(a,c){f=a;l=c});g(a,d.resolvers,f,!0);g(c,d.rejectors,l,!1);return k};x.prototype["catch"]=function(a){return this.then(null,a)};x.resolve=function(a){return a instanceof x?a:new x(function(c){c(a)})};x.reject=function(a){return new x(function(c,g){g(a)})};x.all=function(a){return new x(function(c,g){var d=a.length,f=0,l=[];if(0===a.length)c([]);else for(var k=
|
||||
0;k<a.length;k++)(function(k){function q(a){f++;l[k]=a;f===d&&c(l)}null==a[k]||"object"!==typeof a[k]&&"function"!==typeof a[k]||"function"!==typeof a[k].then?q(a[k]):a[k].then(q,g)})(k)})};x.race=function(a){return new x(function(c,g){for(var d=0;d<a.length;d++)a[d].then(c,g)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=x),x=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise&&(global.Promise=x),x=global.Promise);var D=function(a){function c(a,
|
||||
d){if(d instanceof Array)for(var f=0;f<d.length;f++)c(a+"["+f+"]",d[f]);else if("[object Object]"===Object.prototype.toString.call(d))for(f in d)c(a+"["+f+"]",d[f]);else g.push(encodeURIComponent(a)+(null!=d&&""!==d?"="+encodeURIComponent(d):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var g=[],d;for(d in a)c(d,a[d]);return g.join("&")},I=function(a,c){function g(){function b(){0===--a&&"function"===typeof u&&u()}var a=0;return function z(c){var d=c.then;c.then=function(){a++;
|
||||
var f=d.apply(c,arguments);f.then(b,function(c){b();if(0===a)throw c;});return z(f)};return c}}function d(b,a){if("string"===typeof b){var c=b;b=a||{};null==b.url&&(b.url=c)}return b}function f(b,a){if(null==a)return b;for(var c=b.match(/:[^\/]+/gi)||[],d=0;d<c.length;d++){var f=c[d].slice(1);null!=a[f]&&(b=b.replace(c[d],a[f]),delete a[f])}return b}function l(a,c){var b=D(c);if(""!==b){var d=0>a.indexOf("?")?"?":"&";a+=d+b}return a}function k(a){try{return""!==a?JSON.parse(a):null}catch(C){throw Error(a);
|
||||
}}function r(a){return a.responseText}function q(a,c){if("function"===typeof a)if(c instanceof Array)for(var b=0;b<c.length;b++)c[b]=new a(c[b]);else return new a(c);return c}var m=0,u;return{request:function(b,m){var u=g();b=d(b,m);var z=new c(function(c,d){null==b.method&&(b.method="GET");b.method=b.method.toUpperCase();var g="boolean"===typeof b.useBody?b.useBody:"GET"!==b.method&&"TRACE"!==b.method;"function"!==typeof b.serialize&&(b.serialize="undefined"!==typeof FormData&&b.data instanceof FormData?
|
||||
function(a){return a}:JSON.stringify);"function"!==typeof b.deserialize&&(b.deserialize=k);"function"!==typeof b.extract&&(b.extract=r);b.url=f(b.url,b.data);g?b.data=b.serialize(b.data):b.url=l(b.url,b.data);var m=new a.XMLHttpRequest;m.open(b.method,b.url,"boolean"===typeof b.async?b.async:!0,"string"===typeof b.user?b.user:void 0,"string"===typeof b.password?b.password:void 0);b.serialize===JSON.stringify&&g&&m.setRequestHeader("Content-Type","application/json; charset=utf-8");b.deserialize===
|
||||
k&&m.setRequestHeader("Accept","application/json, text/*");b.withCredentials&&(m.withCredentials=b.withCredentials);"function"===typeof b.config&&(m=b.config(m,b)||m);m.onreadystatechange=function(){if(4===m.readyState)try{var a=b.extract!==r?b.extract(m,b):b.deserialize(b.extract(m,b));if(200<=m.status&&300>m.status||304===m.status)c(q(b.type,a));else{var f=Error(m.responseText),g;for(g in a)f[g]=a[g];d(f)}}catch(e){d(e)}};g&&null!=b.data?m.send(b.data):m.send()});return!0===b.background?z:u(z)},
|
||||
jsonp:function(b,k){var r=g();b=d(b,k);var u=new c(function(c,d){var g=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,k=a.document.createElement("script");a[g]=function(d){k.parentNode.removeChild(k);c(q(b.type,d));delete a[g]};k.onerror=function(){k.parentNode.removeChild(k);d(Error("JSONP request failed"));delete a[g]};null==b.data&&(b.data={});b.url=f(b.url,b.data);b.data[b.callbackKey||"callback"]=g;k.src=l(b.url,b.data);a.document.documentElement.appendChild(k)});return!0===
|
||||
b.background?u:r(u)},setCompletionCallback:function(a){u=a}}}(window,x),M=function(a){function c(e,h,a,b,c,d,f){for(;a<b;a++){var p=h[a];null!=p&&m(e,g(p,c,f),d)}}function g(e,h,a){var p=e.tag;null!=e.attrs&&H(e.attrs,e,h);if("string"===typeof p)switch(p){case "#":return e.dom=B.createTextNode(e.children);case "<":return d(e);case "[":var b=B.createDocumentFragment();null!=e.children&&(p=e.children,c(b,p,0,p.length,h,null,a));e.dom=b.firstChild;e.domSize=b.childNodes.length;return b;default:var g=
|
||||
e.tag;switch(e.tag){case "svg":a="http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}var m=(p=e.attrs)&&p.is,g=a?m?B.createElementNS(a,g,{is:m}):B.createElementNS(a,g):m?B.createElement(g,{is:m}):B.createElement(g);e.dom=g;if(null!=p)for(b in m=a,p)z(e,b,null,p[b],m);null!=e.attrs&&null!=e.attrs.contenteditable?u(e):(null!=e.text&&(""!==e.text?g.textContent=e.text:e.children=[w("#",void 0,void 0,e.text,void 0,void 0)]),null!=e.children&&(b=e.children,c(g,b,0,b.length,
|
||||
h,null,a),h=e.attrs,"select"===e.tag&&null!=h&&("value"in h&&z(e,"value",null,h.value,void 0),"selectedIndex"in h&&z(e,"selectedIndex",null,h.selectedIndex,void 0))));return g}else return f(e,h,a)}function d(e){var h={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(e.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",h=B.createElement(h);h.innerHTML=e.children;e.dom=h.firstChild;e.domSize=h.childNodes.length;e=B.createDocumentFragment();
|
||||
for(var a;a=h.firstChild;)e.appendChild(a);return e}function f(e,h,a){e.state||(e.state={});var b=function(){};b.prototype=e.tag;e.state=new b;b=e.tag.view;if(null!=b.reentrantLock)return L;b.reentrantLock=!0;H(e.tag,e,h);e.instance=w.normalize(b.call(e.state,e));b.reentrantLock=null;if(null!=e.instance){if(e.instance===e)throw Error("A view cannot return the vnode it received as arguments");h=g(e.instance,h,a);e.dom=e.instance.dom;e.domSize=null!=e.dom?e.instance.domSize:0;return h}e.domSize=0;return L}
|
||||
function l(e,a,p,d,f,l){if(a!==p&&(null!=a||null!=p))if(null==a)c(e,p,0,p.length,d,f,void 0);else if(null==p)b(a,0,a.length,p);else{if(a.length===p.length){for(var h=!1,t=0;t<p.length;t++)if(null!=p[t]&&null!=a[t]){h=null==p[t].key&&null==a[t].key;break}if(h){for(t=0;t<a.length;t++)a[t]!==p[t]&&(null==a[t]&&null!=p[t]?m(e,g(p[t],d,l),q(a,t+1,f)):null==p[t]?b(a,t,t+1,p):k(e,a[t],p[t],d,q(a,t+1,f),!1,l));return}}a:{if(null!=a.pool&&Math.abs(a.pool.length-p.length)<=Math.abs(a.length-p.length)&&(h=p[0]&&
|
||||
p[0].children&&p[0].children.length||0,Math.abs((a.pool[0]&&a.pool[0].children&&a.pool[0].children.length||0)-h)<=Math.abs((a[0]&&a[0].children&&a[0].children.length||0)-h))){h=!0;break a}h=!1}h&&(a=a.concat(a.pool));for(var u=t=0,v=a.length-1,z=p.length-1,C;v>=t&&z>=u;){var y=a[t],n=p[u];if(y!==n||h)if(null==y)t++;else if(null==n)u++;else if(y.key===n.key)t++,u++,k(e,y,n,d,q(a,t,f),h,l),h&&y.tag===n.tag&&m(e,r(y),f);else if(y=a[v],y!==n||h)if(null==y)v--;else if(null==n)u++;else if(y.key===n.key)k(e,
|
||||
y,n,d,q(a,v+1,f),h,l),(h||u<z)&&m(e,r(y),q(a,t,f)),v--,u++;else break;else v--,u++;else t++,u++}for(;v>=t&&z>=u;){y=a[v];n=p[z];if(y!==n||h)if(null==y)v--;else{if(null!=n)if(y.key===n.key)k(e,y,n,d,q(a,v+1,f),h,l),h&&y.tag===n.tag&&m(e,r(y),f),null!=y.dom&&(f=y.dom),v--;else{if(!C){C=a;var y=v,E={},w;for(w=0;w<y;w++){var x=C[w];null!=x&&(x=x.key,null!=x&&(E[x]=w))}C=E}null!=n&&(y=C[n.key],null!=y?(E=a[y],k(e,E,n,d,q(a,v+1,f),h,l),m(e,r(E),f),a[y].skip=!0,null!=E.dom&&(f=E.dom)):(n=g(n,d,void 0),m(e,
|
||||
n,f),f=n))}z--}else v--,z--;if(z<u)break}c(e,p,u,z+1,d,f,l);b(a,t,v+1,p)}}function k(a,h,b,c,f,q,n){var e=h.tag;if(e===b.tag){b.state=h.state;b.events=h.events;var p;var t;null!=b.attrs&&"function"===typeof b.attrs.onbeforeupdate&&(p=b.attrs.onbeforeupdate.call(b.state,b,h));"string"!==typeof b.tag&&"function"===typeof b.tag.onbeforeupdate&&(t=b.tag.onbeforeupdate.call(b.state,b,h));void 0===p&&void 0===t||p||t?p=!1:(b.dom=h.dom,b.domSize=h.domSize,b.instance=h.instance,p=!0);if(!p)if(null!=b.attrs&&
|
||||
K(b.attrs,b,c,q),"string"===typeof e)switch(e){case "#":h.children.toString()!==b.children.toString()&&(h.dom.nodeValue=b.children);b.dom=h.dom;break;case "<":h.children!==b.children?(r(h),m(a,d(b),f)):(b.dom=h.dom,b.domSize=h.domSize);break;case "[":l(a,h.children,b.children,c,f,n);h=0;c=b.children;b.dom=null;if(null!=c){for(var v=0;v<c.length;v++)a=c[v],null!=a&&null!=a.dom&&(null==b.dom&&(b.dom=a.dom),h+=a.domSize||1);1!==h&&(b.domSize=h)}break;default:a=n;f=b.dom=h.dom;switch(b.tag){case "svg":a=
|
||||
"http://www.w3.org/2000/svg";break;case "math":a="http://www.w3.org/1998/Math/MathML"}"textarea"===b.tag&&(null==b.attrs&&(b.attrs={}),null!=b.text&&(b.attrs.value=b.text,b.text=void 0));q=h.attrs;n=b.attrs;e=a;if(null!=n)for(v in n)z(b,v,q&&q[v],n[v],e);if(null!=q)for(v in q)null!=n&&v in n||("className"===v&&(v="class"),"o"!==v[0]||"n"!==v[1]||x(v)?"key"!==v&&b.dom.removeAttribute(v):A(b,v,void 0));null!=b.attrs&&null!=b.attrs.contenteditable?u(b):null!=h.text&&null!=b.text&&""!==b.text?h.text.toString()!==
|
||||
b.text.toString()&&(h.dom.firstChild.nodeValue=b.text):(null!=h.text&&(h.children=[w("#",void 0,void 0,h.text,void 0,h.dom.firstChild)]),null!=b.text&&(b.children=[w("#",void 0,void 0,b.text,void 0,void 0)]),l(f,h.children,b.children,c,null,a))}else b.instance=w.normalize(b.tag.view.call(b.state,b)),K(b.tag,b,c,q),null!=b.instance?(null==h.instance?m(a,g(b.instance,c,n),f):k(a,h.instance,b.instance,c,f,q,n),b.dom=b.instance.dom,b.domSize=b.instance.domSize):null!=h.instance?(C(h.instance,null),b.dom=
|
||||
void 0,b.domSize=0):(b.dom=h.dom,b.domSize=h.domSize)}else C(h,null),m(a,g(b,c,n),f)}function r(a){var b=a.domSize;if(null!=b||null==a.dom){var e=B.createDocumentFragment();if(0<b){for(a=a.dom;--b;)e.appendChild(a.nextSibling);e.insertBefore(a,e.firstChild)}return e}return a.dom}function q(a,b,c){for(;b<a.length;b++)if(null!=a[b]&&null!=a[b].dom)return a[b].dom;return c}function m(a,b,c){c&&c.parentNode?a.insertBefore(b,c):a.appendChild(b)}function u(a){var b=a.children;if(null!=b&&1===b.length&&
|
||||
"<"===b[0].tag)b=b[0].children,a.dom.innerHTML!==b&&(a.dom.innerHTML=b);else if(null!=a.text||null!=b&&0!==b.length)throw Error("Child node of a contenteditable must be trusted");}function b(a,b,c,d){for(;b<c;b++){var e=a[b];null!=e&&(e.skip?e.skip=!1:C(e,d))}}function C(a,b){function e(){if(++h===c&&(n(a),a.dom)){var e=a.domSize||1;if(1<e)for(var d=a.dom;--e;){var f=d.nextSibling,g=f.parentNode;null!=g&&g.removeChild(f)}e=a.dom;d=e.parentNode;null!=d&&d.removeChild(e);if(e=null!=b&&null==a.domSize)e=
|
||||
a.attrs,e=!(null!=e&&(e.oncreate||e.onupdate||e.onbeforeremove||e.onremove));e&&"string"===typeof a.tag&&(b.pool?b.pool.push(a):b.pool=[a])}}var c=1,h=0;if(a.attrs&&a.attrs.onbeforeremove){var d=a.attrs.onbeforeremove.call(a.state,a);null!=d&&"function"===typeof d.then&&(c++,d.then(e,e))}"string"!==typeof a.tag&&a.tag.onbeforeremove&&(d=a.tag.onbeforeremove.call(a.state,a),null!=d&&"function"===typeof d.then&&(c++,d.then(e,e)));e()}function n(a){a.attrs&&a.attrs.onremove&&a.attrs.onremove.call(a.state,
|
||||
a);"string"!==typeof a.tag&&a.tag.onremove&&a.tag.onremove.call(a.state,a);if(null!=a.instance)n(a.instance);else if(a=a.children,a instanceof Array)for(var b=0;b<a.length;b++){var e=a[b];null!=e&&n(e)}}function z(a,b,c,d,f){var e=a.dom;if("key"!==b&&"is"!==b&&(c!==d||"value"===b||"checked"===b||"selectedIndex"===b||"selected"===b&&a.dom===B.activeElement||"object"===typeof d)&&"undefined"!==typeof d&&!x(b)){var h=b.indexOf(":");if(-1<h&&"xlink"===b.substr(0,h))e.setAttributeNS("http://www.w3.org/1999/xlink",
|
||||
b.slice(h+1),d);else if("o"===b[0]&&"n"===b[1]&&"function"===typeof d)A(a,b,d);else if("style"===b)if(a=c,a===d&&(e.style.cssText="",a=null),null==d)e.style.cssText="";else if("string"===typeof d)e.style.cssText=d;else{"string"===typeof a&&(e.style.cssText="");for(var g in d)e.style[g]=d[g];if(null!=a&&"string"!==typeof a)for(g in a)g in d||(e.style[g]="")}else b in e&&"href"!==b&&"list"!==b&&"form"!==b&&"width"!==b&&"height"!==b&&void 0===f&&!(a.attrs.is||-1<a.tag.indexOf("-"))?"input"===a.tag&&
|
||||
"value"===b&&a.dom.value===d&&a.dom===B.activeElement||"select"===a.tag&&"value"===b&&a.dom.value===d&&a.dom===B.activeElement||"option"===a.tag&&"value"===b&&a.dom.value===d||(e[b]=d):"boolean"===typeof d?d?e.setAttribute(b,""):e.removeAttribute(b):e.setAttribute("className"===b?"class":b,d)}}function x(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function A(a,b,c){var e=a.dom,d="function"!==typeof D?c:function(a){var b=c.call(e,
|
||||
a);D.call(e,a);return b};if(b in e)e[b]="function"===typeof c?d:null;else{var f=b.slice(2);void 0===a.events&&(a.events={});a.events[b]!==d&&(null!=a.events[b]&&e.removeEventListener(f,a.events[b],!1),"function"===typeof c&&(a.events[b]=d,e.addEventListener(f,a.events[b],!1)))}}function H(a,b,c){"function"===typeof a.oninit&&a.oninit.call(b.state,b);"function"===typeof a.oncreate&&c.push(a.oncreate.bind(b.state,b))}function K(a,b,c,d){d?H(a,b,c):"function"===typeof a.onupdate&&c.push(a.onupdate.bind(b.state,
|
||||
b))}var B=a.document,L=B.createDocumentFragment(),D;return{render:function(a,b){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var c=[],d=B.activeElement;null==a.vnodes&&(a.textContent="");b instanceof Array||(b=[b]);l(a,a.vnodes,w.normalizeChildren(b),c,null,void 0);a.vnodes=b;for(var e=0;e<c.length;e++)c[e]();B.activeElement!==d&&d.focus()},setEventCallback:function(a){return D=a}}},F=function(a){function c(a){a=d.indexOf(a);-1<a&&d.splice(a,
|
||||
2)}function g(){for(var a=1;a<d.length;a+=2)d[a]()}a=M(a);a.setEventCallback(function(a){!1!==a.redraw&&g()});var d=[];return{subscribe:function(a,g){c(a);d.push(a,O(g))},unsubscribe:c,redraw:g,render:a.render}}(window);I.setCompletionCallback(F.redraw);A.mount=function(a){return function(c,g){if(null===g)a.render(c,[]),a.unsubscribe(c);else{if(null==g.view)throw Error("m.mount(element, component) expects a component, not a vnode");a.subscribe(c,function(){a.render(c,w(g))});a.redraw()}}}(F);var Q=
|
||||
x,J=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var c={},g={},d=0;d<a.length;d++){var f=a[d].split("="),l=decodeURIComponent(f[0]),f=2===f.length?decodeURIComponent(f[1]):"";"true"===f?f=!0:"false"===f&&(f=!1);var k=l.split(/\]\[?|\[/),r=c;-1<l.indexOf("[")&&k.pop();for(var q=0;q<k.length;q++){var l=k[q],m=k[q+1],m=""==m||!isNaN(parseInt(m,10)),u=q===k.length-1;""===l&&(l=k.slice(0,q).join(),null==g[l]&&(g[l]=0),l=g[l]++);null==r[l]&&(r[l]=u?f:m?[]:
|
||||
{});r=r[l]}}return c},R=function(a){function c(c){var d=a.location[c].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===c&&"/"!==d[0]&&(d="/"+d);return d}function g(a){return function(){null==k&&(k=l(function(){k=null;a()}))}}function d(a,c,d){var b=a.indexOf("?"),f=a.indexOf("#"),g=-1<b?b:-1<f?f:a.length;if(-1<b){var b=J(a.slice(b+1,-1<f?f:a.length)),k;for(k in b)c[k]=b[k]}if(-1<f)for(k in c=J(a.slice(f+1)),c)d[k]=c[k];return a.slice(0,g)}var f="function"===typeof a.history.pushState,
|
||||
l="function"===typeof setImmediate?setImmediate:setTimeout,k,r={prefix:"#!",getPath:function(){switch(r.prefix.charAt(0)){case "#":return c("hash").slice(r.prefix.length);case "?":return c("search").slice(r.prefix.length)+c("hash");default:return c("pathname").slice(r.prefix.length)+c("search")+c("hash")}},setPath:function(c,g,k){var b={},l={};c=d(c,b,l);if(null!=g){for(var n in g)b[n]=g[n];c=c.replace(/:([^\/]+)/g,function(a,c){delete b[c];return g[c]})}(n=D(b))&&(c+="?"+n);(l=D(l))&&(c+="#"+l);
|
||||
f?(l=k?k.state:null,n=k?k.title:null,a.onpopstate(),k&&k.replace?a.history.replaceState(l,n,r.prefix+c):a.history.pushState(l,n,r.prefix+c)):a.location.href=r.prefix+c},defineRoutes:function(c,k,l){function b(){var b=r.getPath(),f={},g=d(b,f,f),m=a.history.state;if(null!=m)for(var q in m)f[q]=m[q];for(var u in c)if(m=new RegExp("^"+u.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),m.test(g)){g.replace(m,function(){for(var a=u.match(/:[^\/]+/g)||[],d=[].slice.call(arguments,
|
||||
1,-2),g=0;g<a.length;g++)f[a[g].replace(/:|\./g,"")]=decodeURIComponent(d[g]);k(c[u],f,b,u)});return}l(b,f)}f?a.onpopstate=g(b):"#"===r.prefix.charAt(0)&&(a.onhashchange=b);b()}};return r};A.route=function(a,c){var g=R(a),d=function(a){return a},f,l,k,r,q,m=function(a,b,m){if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var n=function(){null!=f&&c.render(a,f(w(l,k.key,k)))},u=function(){g.setPath(b,null,{replace:!0})};g.defineRoutes(m,function(a,b,c){var g=
|
||||
q=function(a,m){g===q&&(l=null!=m&&"function"===typeof m.view?m:"div",k=b,r=c,q=null,f=(a.render||d).bind(a),n())};a.view?g({},a):a.onmatch?Q.resolve(a.onmatch(b,c)).then(function(b){g(a,b)},u):g(a,"div")},u);c.subscribe(a,n)};m.set=function(a,b,c){null!=q&&(c={replace:!0});q=null;g.setPath(a,b,c)};m.get=function(){return r};m.prefix=function(a){g.prefix=a};m.link=function(a){a.dom.setAttribute("href",g.prefix+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(g.prefix)&&(a=a.slice(g.prefix.length)),m.set(a,void 0,void 0))}};return m}(window,F);A.withAttr=function(a,c,g){return function(d){return c.call(g||this,a in d.currentTarget?d.currentTarget[a]:d.currentTarget.getAttribute(a))}};var S=M(window);A.render=S.render;A.redraw=F.redraw;A.request=I.request;A.jsonp=I.jsonp;A.parseQueryString=J;A.buildQueryString=D;A.version="1.0.0-rc.7";A.vnode=w;"undefined"!==typeof module?module.exports=
|
||||
A:window.m=A};
|
||||
new function(){function w(b,c,h,d,g,l){return{tag:b,key:c,attrs:h,children:d,text:g,dom:l,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function A(b){if(null==b||"string"!==typeof b&&null==b.view)throw Error("The selector must be either a string or a component.");if("string"===typeof b&&void 0===G[b]){for(var c,h,d=[],g={};c=N.exec(b);){var l=c[1],m=c[2];""===l&&""!==m?h=m:"#"===l?g.id=m:"."===l?d.push(m):"["===c[3][0]&&((l=c[6])&&(l=l.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),
|
||||
"class"===c[4]?d.push(l):g[c[4]]=l||!0)}0<d.length&&(g.className=d.join(" "));G[b]=function(b,c){var d=!1,a,l,n=b.className||b["class"],z;for(z in g)b[z]=g[z];void 0!==n&&(void 0!==b["class"]&&(b["class"]=void 0,b.className=n),void 0!==g.className&&(b.className=g.className+" "+n));for(z in b)if("key"!==z){d=!0;break}c instanceof Array&&1==c.length&&null!=c[0]&&"#"===c[0].tag?l=c[0].children:a=c;return w(h||"div",b.key,d?b:void 0,a,l,void 0)}}var q;null!=arguments[1]&&("object"!==typeof arguments[1]||
|
||||
void 0!==arguments[1].tag||arguments[1]instanceof Array)?d=1:(q=arguments[1],d=2);if(arguments.length===d+1)c=arguments[d]instanceof Array?arguments[d]:[arguments[d]];else for(c=[];d<arguments.length;d++)c.push(arguments[d]);return"string"===typeof b?G[b](q||{},w.normalizeChildren(c)):w(b,q&&q.key,q||{},w.normalizeChildren(c),void 0,void 0)}function O(b){var c=0,h=null,d="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var g=Date.now();0===c||16<=g-c?(c=
|
||||
g,b()):null===h&&(h=d(function(){h=null;b();c=Date.now()},16-(g-c)))}}w.normalize=function(b){return b instanceof Array?w("[",void 0,void 0,w.normalizeChildren(b),void 0,void 0):null!=b&&"object"!==typeof b?w("#",void 0,void 0,b,void 0,void 0):b};w.normalizeChildren=function(b){for(var c=0;c<b.length;c++)b[c]=w.normalize(b[c]);return b};var N=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,G={};A.trust=function(b){null==b&&(b="");return w("<",void 0,void 0,b,void 0,
|
||||
void 0)};A.fragment=function(b,c){return w("[",b.key,b,w.normalizeChildren(c),void 0,void 0)};var x=function(b){function c(b,a){return function p(c){var m;try{if(!a||null==c||"object"!==typeof c&&"function"!==typeof c||"function"!==typeof(m=c.then))k(function(){a||0!==b.length||console.error("Possible unhandled promise rejection:",c);for(var d=0;d<b.length;d++)b[d](c);g.length=0;l.length=0;n.state=a;n.retry=function(){p(c)}});else{if(c===d)throw new TypeError("Promise can't be resolved w/ itself");
|
||||
h(m.bind(c))}}catch(P){q(P)}}}function h(b){function a(a){return function(b){0<c++||a(b)}}var c=0,d=a(q);try{b(a(m),d)}catch(z){d(z)}}if(!(this instanceof x))throw Error("Promise must be called with `new`");if("function"!==typeof b)throw new TypeError("executor must be a function");var d=this,g=[],l=[],m=c(g,!0),q=c(l,!1),n=d._instance={resolvers:g,rejectors:l},k="function"===typeof setImmediate?setImmediate:setTimeout;h(b)};x.prototype.then=function(b,c){function h(b,c,h,m){c.push(function(a){if("function"!==
|
||||
typeof b)h(a);else try{g(b(a))}catch(C){l&&l(C)}});"function"===typeof d.retry&&m===d.state&&d.retry()}var d=this._instance,g,l,m=new x(function(b,c){g=b;l=c});h(b,d.resolvers,g,!0);h(c,d.rejectors,l,!1);return m};x.prototype["catch"]=function(b){return this.then(null,b)};x.resolve=function(b){return b instanceof x?b:new x(function(c){c(b)})};x.reject=function(b){return new x(function(c,h){h(b)})};x.all=function(b){return new x(function(c,h){var d=b.length,g=0,l=[];if(0===b.length)c([]);else for(var m=
|
||||
0;m<b.length;m++)(function(m){function n(b){g++;l[m]=b;g===d&&c(l)}null==b[m]||"object"!==typeof b[m]&&"function"!==typeof b[m]||"function"!==typeof b[m].then?n(b[m]):b[m].then(n,h)})(m)})};x.race=function(b){return new x(function(c,h){for(var d=0;d<b.length;d++)b[d].then(c,h)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=x),x=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise&&(global.Promise=x),x=global.Promise);var D=function(b){function c(b,
|
||||
d){if(d instanceof Array)for(var g=0;g<d.length;g++)c(b+"["+g+"]",d[g]);else if("[object Object]"===Object.prototype.toString.call(d))for(g in d)c(b+"["+g+"]",d[g]);else h.push(encodeURIComponent(b)+(null!=d&&""!==d?"="+encodeURIComponent(d):""))}if("[object Object]"!==Object.prototype.toString.call(b))return"";var h=[],d;for(d in b)c(d,b[d]);return h.join("&")},I=function(b,c){function h(){function a(){0===--b&&"function"===typeof t&&t()}var b=0;return function z(c){var d=c.then;c.then=function(){b++;
|
||||
var g=d.apply(c,arguments);g.then(a,function(c){a();if(0===b)throw c;});return z(g)};return c}}function d(a,b){if("string"===typeof a){var c=a;a=b||{};null==a.url&&(a.url=c)}return a}function g(a,b){if(null==b)return a;for(var c=a.match(/:[^\/]+/gi)||[],d=0;d<c.length;d++){var g=c[d].slice(1);null!=b[g]&&(a=a.replace(c[d],b[g]),delete b[g])}return a}function l(a,b){var c=D(b);if(""!==c){var d=0>a.indexOf("?")?"?":"&";a+=d+c}return a}function m(b){try{return""!==b?JSON.parse(b):null}catch(C){throw Error(b);
|
||||
}}function q(b){return b.responseText}function n(b,c){if("function"===typeof b)if(c instanceof Array)for(var a=0;a<c.length;a++)c[a]=new b(c[a]);else return new b(c);return c}var k=0,t;return{request:function(a,k){var t=h();a=d(a,k);var z=new c(function(c,d){null==a.method&&(a.method="GET");a.method=a.method.toUpperCase();var h="boolean"===typeof a.useBody?a.useBody:"GET"!==a.method&&"TRACE"!==a.method;"function"!==typeof a.serialize&&(a.serialize="undefined"!==typeof FormData&&a.data instanceof FormData?
|
||||
function(b){return b}:JSON.stringify);"function"!==typeof a.deserialize&&(a.deserialize=m);"function"!==typeof a.extract&&(a.extract=q);a.url=g(a.url,a.data);h?a.data=a.serialize(a.data):a.url=l(a.url,a.data);var k=new b.XMLHttpRequest;k.open(a.method,a.url,"boolean"===typeof a.async?a.async:!0,"string"===typeof a.user?a.user:void 0,"string"===typeof a.password?a.password:void 0);a.serialize===JSON.stringify&&h&&k.setRequestHeader("Content-Type","application/json; charset=utf-8");a.deserialize===
|
||||
m&&k.setRequestHeader("Accept","application/json, text/*");a.withCredentials&&(k.withCredentials=a.withCredentials);for(var t in a.headers)({}).hasOwnProperty.call(a.headers,t)&&k.setRequestHeader(t,a.headers[t]);"function"===typeof a.config&&(k=a.config(k,a)||k);k.onreadystatechange=function(){if(4===k.readyState)try{var b=a.extract!==q?a.extract(k,a):a.deserialize(a.extract(k,a));if(200<=k.status&&300>k.status||304===k.status)c(n(a.type,b));else{var g=Error(k.responseText),e;for(e in b)g[e]=b[e];
|
||||
d(g)}}catch(f){d(f)}};h&&null!=a.data?k.send(a.data):k.send()});return!0===a.background?z:t(z)},jsonp:function(a,m){var t=h();a=d(a,m);var q=new c(function(c,d){var h=a.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+k++,m=b.document.createElement("script");b[h]=function(d){m.parentNode.removeChild(m);c(n(a.type,d));delete b[h]};m.onerror=function(){m.parentNode.removeChild(m);d(Error("JSONP request failed"));delete b[h]};null==a.data&&(a.data={});a.url=g(a.url,a.data);a.data[a.callbackKey||
|
||||
"callback"]=h;m.src=l(a.url,a.data);b.document.documentElement.appendChild(m)});return!0===a.background?q:t(q)},setCompletionCallback:function(b){t=b}}}(window,x),M=function(b){function c(e,f,b,a,c,d,g){for(;b<a;b++){var r=f[b];null!=r&&k(e,h(r,c,g),d)}}function h(e,f,b){var a=e.tag;null!=e.attrs&&H(e.attrs,e,f);if("string"===typeof a)switch(a){case "#":return e.dom=B.createTextNode(e.children);case "<":return d(e);case "[":var r=B.createDocumentFragment();null!=e.children&&(a=e.children,c(r,a,0,
|
||||
a.length,f,null,b));e.dom=r.firstChild;e.domSize=r.childNodes.length;return r;default:var h=e.tag;switch(e.tag){case "svg":b="http://www.w3.org/2000/svg";break;case "math":b="http://www.w3.org/1998/Math/MathML"}var k=(a=e.attrs)&&a.is,h=b?k?B.createElementNS(b,h,{is:k}):B.createElementNS(b,h):k?B.createElement(h,{is:k}):B.createElement(h);e.dom=h;if(null!=a)for(r in k=b,a)z(e,r,null,a[r],k);null!=e.attrs&&null!=e.attrs.contenteditable?t(e):(null!=e.text&&(""!==e.text?h.textContent=e.text:e.children=
|
||||
[w("#",void 0,void 0,e.text,void 0,void 0)]),null!=e.children&&(r=e.children,c(h,r,0,r.length,f,null,b),f=e.attrs,"select"===e.tag&&null!=f&&("value"in f&&z(e,"value",null,f.value,void 0),"selectedIndex"in f&&z(e,"selectedIndex",null,f.selectedIndex,void 0))));return h}else return g(e,f,b)}function d(e){var f={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(e.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div",f=B.createElement(f);
|
||||
f.innerHTML=e.children;e.dom=f.firstChild;e.domSize=f.childNodes.length;e=B.createDocumentFragment();for(var b;b=f.firstChild;)e.appendChild(b);return e}function g(e,f,b){e.state||(e.state={});var a=function(){};a.prototype=e.tag;e.state=new a;a=e.tag.view;if(null!=a.reentrantLock)return L;a.reentrantLock=!0;H(e.tag,e,f);e.instance=w.normalize(a.call(e.state,e));a.reentrantLock=null;if(null!=e.instance){if(e.instance===e)throw Error("A view cannot return the vnode it received as arguments");f=h(e.instance,
|
||||
f,b);e.dom=e.instance.dom;e.domSize=null!=e.dom?e.instance.domSize:0;return f}e.domSize=0;return L}function l(e,f,b,d,g,l){if(f!==b&&(null!=f||null!=b))if(null==f)c(e,b,0,b.length,d,g,void 0);else if(null==b)a(f,0,f.length,b);else{if(f.length===b.length){for(var r=!1,u=0;u<b.length;u++)if(null!=b[u]&&null!=f[u]){r=null==b[u].key&&null==f[u].key;break}if(r){for(u=0;u<f.length;u++)f[u]!==b[u]&&(null==f[u]&&null!=b[u]?k(e,h(b[u],d,l),n(f,u+1,g)):null==b[u]?a(f,u,u+1,b):m(e,f[u],b[u],d,n(f,u+1,g),!1,
|
||||
l));return}}a:{if(null!=f.pool&&Math.abs(f.pool.length-b.length)<=Math.abs(f.length-b.length)&&(r=b[0]&&b[0].children&&b[0].children.length||0,Math.abs((f.pool[0]&&f.pool[0].children&&f.pool[0].children.length||0)-r)<=Math.abs((f[0]&&f[0].children&&f[0].children.length||0)-r))){r=!0;break a}r=!1}r&&(f=f.concat(f.pool));for(var t=u=0,v=f.length-1,z=b.length-1,C;v>=u&&z>=t;){var y=f[u],p=b[t];if(y!==p||r)if(null==y)u++;else if(null==p)t++;else if(y.key===p.key)u++,t++,m(e,y,p,d,n(f,u,g),r,l),r&&y.tag===
|
||||
p.tag&&k(e,q(y),g);else if(y=f[v],y!==p||r)if(null==y)v--;else if(null==p)t++;else if(y.key===p.key)m(e,y,p,d,n(f,v+1,g),r,l),(r||t<z)&&k(e,q(y),n(f,u,g)),v--,t++;else break;else v--,t++;else u++,t++}for(;v>=u&&z>=t;){y=f[v];p=b[z];if(y!==p||r)if(null==y)v--;else{if(null!=p)if(y.key===p.key)m(e,y,p,d,n(f,v+1,g),r,l),r&&y.tag===p.tag&&k(e,q(y),g),null!=y.dom&&(g=y.dom),v--;else{if(!C){C=f;var y=v,E={},w;for(w=0;w<y;w++){var x=C[w];null!=x&&(x=x.key,null!=x&&(E[x]=w))}C=E}null!=p&&(y=C[p.key],null!=
|
||||
y?(E=f[y],m(e,E,p,d,n(f,v+1,g),r,l),k(e,q(E),g),f[y].skip=!0,null!=E.dom&&(g=E.dom)):(p=h(p,d,void 0),k(e,p,g),g=p))}z--}else v--,z--;if(z<t)break}c(e,b,t,z+1,d,g,l);a(f,u,v+1,b)}}function m(b,f,a,c,g,n,p){var e=f.tag;if(e===a.tag){a.state=f.state;a.events=f.events;var r;var u;null!=a.attrs&&"function"===typeof a.attrs.onbeforeupdate&&(r=a.attrs.onbeforeupdate.call(a.state,a,f));"string"!==typeof a.tag&&"function"===typeof a.tag.onbeforeupdate&&(u=a.tag.onbeforeupdate.call(a.state,a,f));void 0===
|
||||
r&&void 0===u||r||u?r=!1:(a.dom=f.dom,a.domSize=f.domSize,a.instance=f.instance,r=!0);if(!r)if(null!=a.attrs&&K(a.attrs,a,c,n),"string"===typeof e)switch(e){case "#":f.children.toString()!==a.children.toString()&&(f.dom.nodeValue=a.children);a.dom=f.dom;break;case "<":f.children!==a.children?(q(f),k(b,d(a),g)):(a.dom=f.dom,a.domSize=f.domSize);break;case "[":l(b,f.children,a.children,c,g,p);f=0;c=a.children;a.dom=null;if(null!=c){for(var v=0;v<c.length;v++)b=c[v],null!=b&&null!=b.dom&&(null==a.dom&&
|
||||
(a.dom=b.dom),f+=b.domSize||1);1!==f&&(a.domSize=f)}break;default:b=p;g=a.dom=f.dom;switch(a.tag){case "svg":b="http://www.w3.org/2000/svg";break;case "math":b="http://www.w3.org/1998/Math/MathML"}"textarea"===a.tag&&(null==a.attrs&&(a.attrs={}),null!=a.text&&(a.attrs.value=a.text,a.text=void 0));n=f.attrs;p=a.attrs;e=b;if(null!=p)for(v in p)z(a,v,n&&n[v],p[v],e);if(null!=n)for(v in n)null!=p&&v in p||("className"===v&&(v="class"),"o"!==v[0]||"n"!==v[1]||x(v)?"key"!==v&&a.dom.removeAttribute(v):A(a,
|
||||
v,void 0));null!=a.attrs&&null!=a.attrs.contenteditable?t(a):null!=f.text&&null!=a.text&&""!==a.text?f.text.toString()!==a.text.toString()&&(f.dom.firstChild.nodeValue=a.text):(null!=f.text&&(f.children=[w("#",void 0,void 0,f.text,void 0,f.dom.firstChild)]),null!=a.text&&(a.children=[w("#",void 0,void 0,a.text,void 0,void 0)]),l(g,f.children,a.children,c,null,b))}else a.instance=w.normalize(a.tag.view.call(a.state,a)),K(a.tag,a,c,n),null!=a.instance?(null==f.instance?k(b,h(a.instance,c,p),g):m(b,
|
||||
f.instance,a.instance,c,g,n,p),a.dom=a.instance.dom,a.domSize=a.instance.domSize):null!=f.instance?(C(f.instance,null),a.dom=void 0,a.domSize=0):(a.dom=f.dom,a.domSize=f.domSize)}else C(f,null),k(b,h(a,c,p),g)}function q(a){var b=a.domSize;if(null!=b||null==a.dom){var e=B.createDocumentFragment();if(0<b){for(a=a.dom;--b;)e.appendChild(a.nextSibling);e.insertBefore(a,e.firstChild)}return e}return a.dom}function n(a,b,c){for(;b<a.length;b++)if(null!=a[b]&&null!=a[b].dom)return a[b].dom;return c}function k(a,
|
||||
b,c){c&&c.parentNode?a.insertBefore(b,c):a.appendChild(b)}function t(a){var b=a.children;if(null!=b&&1===b.length&&"<"===b[0].tag)b=b[0].children,a.dom.innerHTML!==b&&(a.dom.innerHTML=b);else if(null!=a.text||null!=b&&0!==b.length)throw Error("Child node of a contenteditable must be trusted");}function a(a,b,c,d){for(;b<c;b++){var e=a[b];null!=e&&(e.skip?e.skip=!1:C(e,d))}}function C(a,b){function e(){if(++c===f&&(p(a),a.dom)){var e=a.domSize||1;if(1<e)for(var d=a.dom;--e;){var g=d.nextSibling,h=
|
||||
g.parentNode;null!=h&&h.removeChild(g)}e=a.dom;d=e.parentNode;null!=d&&d.removeChild(e);if(e=null!=b&&null==a.domSize)e=a.attrs,e=!(null!=e&&(e.oncreate||e.onupdate||e.onbeforeremove||e.onremove));e&&"string"===typeof a.tag&&(b.pool?b.pool.push(a):b.pool=[a])}}var f=1,c=0;if(a.attrs&&a.attrs.onbeforeremove){var d=a.attrs.onbeforeremove.call(a.state,a);null!=d&&"function"===typeof d.then&&(f++,d.then(e,e))}"string"!==typeof a.tag&&a.tag.onbeforeremove&&(d=a.tag.onbeforeremove.call(a.state,a),null!=
|
||||
d&&"function"===typeof d.then&&(f++,d.then(e,e)));e()}function p(a){a.attrs&&a.attrs.onremove&&a.attrs.onremove.call(a.state,a);"string"!==typeof a.tag&&a.tag.onremove&&a.tag.onremove.call(a.state,a);if(null!=a.instance)p(a.instance);else if(a=a.children,a instanceof Array)for(var b=0;b<a.length;b++){var e=a[b];null!=e&&p(e)}}function z(a,b,c,d,g){var e=a.dom;if("key"!==b&&"is"!==b&&(c!==d||"value"===b||"checked"===b||"selectedIndex"===b||"selected"===b&&a.dom===B.activeElement||"object"===typeof d)&&
|
||||
"undefined"!==typeof d&&!x(b)){var f=b.indexOf(":");if(-1<f&&"xlink"===b.substr(0,f))e.setAttributeNS("http://www.w3.org/1999/xlink",b.slice(f+1),d);else if("o"===b[0]&&"n"===b[1]&&"function"===typeof d)A(a,b,d);else if("style"===b)if(a=c,a===d&&(e.style.cssText="",a=null),null==d)e.style.cssText="";else if("string"===typeof d)e.style.cssText=d;else{"string"===typeof a&&(e.style.cssText="");for(var h in d)e.style[h]=d[h];if(null!=a&&"string"!==typeof a)for(h in a)h in d||(e.style[h]="")}else b in
|
||||
e&&"href"!==b&&"list"!==b&&"form"!==b&&"width"!==b&&"height"!==b&&void 0===g&&!(a.attrs.is||-1<a.tag.indexOf("-"))?"input"===a.tag&&"value"===b&&a.dom.value===d&&a.dom===B.activeElement||"select"===a.tag&&"value"===b&&a.dom.value===d&&a.dom===B.activeElement||"option"===a.tag&&"value"===b&&a.dom.value===d||(e[b]=d):"boolean"===typeof d?d?e.setAttribute(b,""):e.removeAttribute(b):e.setAttribute("className"===b?"class":b,d)}}function x(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===
|
||||
a||"onbeforeremove"===a||"onbeforeupdate"===a}function A(a,b,c){var e=a.dom,d="function"!==typeof D?c:function(a){var b=c.call(e,a);D.call(e,a);return b};if(b in e)e[b]="function"===typeof c?d:null;else{var f=b.slice(2);void 0===a.events&&(a.events={});a.events[b]!==d&&(null!=a.events[b]&&e.removeEventListener(f,a.events[b],!1),"function"===typeof c&&(a.events[b]=d,e.addEventListener(f,a.events[b],!1)))}}function H(a,b,c){"function"===typeof a.oninit&&a.oninit.call(b.state,b);"function"===typeof a.oncreate&&
|
||||
c.push(a.oncreate.bind(b.state,b))}function K(a,b,c,d){d?H(a,b,c):"function"===typeof a.onupdate&&c.push(a.onupdate.bind(b.state,b))}var B=b.document,L=B.createDocumentFragment(),D;return{render:function(a,b){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var c=[],d=B.activeElement;null==a.vnodes&&(a.textContent="");b instanceof Array||(b=[b]);l(a,a.vnodes,w.normalizeChildren(b),c,null,void 0);a.vnodes=b;for(var e=0;e<c.length;e++)c[e]();B.activeElement!==
|
||||
d&&d.focus()},setEventCallback:function(a){return D=a}}},F=function(b){function c(b){b=d.indexOf(b);-1<b&&d.splice(b,2)}function h(){for(var b=1;b<d.length;b+=2)d[b]()}b=M(b);b.setEventCallback(function(b){!1!==b.redraw&&h()});var d=[];return{subscribe:function(b,h){c(b);d.push(b,O(h))},unsubscribe:c,redraw:h,render:b.render}}(window);I.setCompletionCallback(F.redraw);A.mount=function(b){return function(c,h){if(null===h)b.render(c,[]),b.unsubscribe(c);else{if(null==h.view)throw Error("m.mount(element, component) expects a component, not a vnode");
|
||||
b.subscribe(c,function(){b.render(c,w(h))});b.redraw()}}}(F);var Q=x,J=function(b){if(""===b||null==b)return{};"?"===b.charAt(0)&&(b=b.slice(1));b=b.split("&");for(var c={},h={},d=0;d<b.length;d++){var g=b[d].split("="),l=decodeURIComponent(g[0]),g=2===g.length?decodeURIComponent(g[1]):"";"true"===g?g=!0:"false"===g&&(g=!1);var m=l.split(/\]\[?|\[/),q=c;-1<l.indexOf("[")&&m.pop();for(var n=0;n<m.length;n++){var l=m[n],k=m[n+1],k=""==k||!isNaN(parseInt(k,10)),t=n===m.length-1;""===l&&(l=m.slice(0,
|
||||
n).join(),null==h[l]&&(h[l]=0),l=h[l]++);null==q[l]&&(q[l]=t?g:k?[]:{});q=q[l]}}return c},R=function(b){function c(c){var d=b.location[c].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===c&&"/"!==d[0]&&(d="/"+d);return d}function h(b){return function(){null==m&&(m=l(function(){m=null;b()}))}}function d(b,c,d){var a=b.indexOf("?"),g=b.indexOf("#"),h=-1<a?a:-1<g?g:b.length;if(-1<a){var a=J(b.slice(a+1,-1<g?g:b.length)),k;for(k in a)c[k]=a[k]}if(-1<g)for(k in c=J(b.slice(g+1)),c)d[k]=
|
||||
c[k];return b.slice(0,h)}var g="function"===typeof b.history.pushState,l="function"===typeof setImmediate?setImmediate:setTimeout,m,q={prefix:"#!",getPath:function(){switch(q.prefix.charAt(0)){case "#":return c("hash").slice(q.prefix.length);case "?":return c("search").slice(q.prefix.length)+c("hash");default:return c("pathname").slice(q.prefix.length)+c("search")+c("hash")}},setPath:function(c,h,m){var a={},k={};c=d(c,a,k);if(null!=h){for(var l in h)a[l]=h[l];c=c.replace(/:([^\/]+)/g,function(b,
|
||||
c){delete a[c];return h[c]})}(l=D(a))&&(c+="?"+l);(k=D(k))&&(c+="#"+k);g?(k=m?m.state:null,l=m?m.title:null,b.onpopstate(),m&&m.replace?b.history.replaceState(k,l,q.prefix+c):b.history.pushState(k,l,q.prefix+c)):b.location.href=q.prefix+c},defineRoutes:function(c,k,m){function a(){var a=q.getPath(),g={},h=d(a,g,g),l=b.history.state;if(null!=l)for(var t in l)g[t]=l[t];for(var n in c)if(l=new RegExp("^"+n.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),l.test(h)){h.replace(l,
|
||||
function(){for(var b=n.match(/:[^\/]+/g)||[],d=[].slice.call(arguments,1,-2),h=0;h<b.length;h++)g[b[h].replace(/:|\./g,"")]=decodeURIComponent(d[h]);k(c[n],g,a,n)});return}m(a,g)}g?b.onpopstate=h(a):"#"===q.prefix.charAt(0)&&(b.onhashchange=a);a()}};return q};A.route=function(b,c){var h=R(b),d=function(b){return b},g,l,m,q,n,k=function(b,a,k){if(null==b)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var p=function(){null!=g&&c.render(b,g(w(l,m.key,m)))},t=function(){h.setPath(a,
|
||||
null,{replace:!0})};h.defineRoutes(k,function(a,b,c){var h=n=function(a,k){h===n&&(l=null!=k&&"function"===typeof k.view?k:"div",m=b,q=c,n=null,g=(a.render||d).bind(a),p())};a.view?h({},a):a.onmatch?Q.resolve(a.onmatch(b,c)).then(function(b){h(a,b)},t):h(a,"div")},t);c.subscribe(b,p)};k.set=function(b,a,c){null!=n&&(c={replace:!0});n=null;h.setPath(b,a,c)};k.get=function(){return q};k.prefix=function(b){h.prefix=b};k.link=function(b){b.dom.setAttribute("href",h.prefix+b.attrs.href);b.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(h.prefix)&&(a=a.slice(h.prefix.length)),k.set(a,void 0,void 0))}};return k}(window,F);A.withAttr=function(b,c,h){return function(d){return c.call(h||this,b in d.currentTarget?d.currentTarget[b]:d.currentTarget.getAttribute(b))}};var S=M(window);A.render=S.render;A.redraw=F.redraw;A.request=I.request;A.jsonp=I.jsonp;A.parseQueryString=J;A.buildQueryString=D;A.version=
|
||||
"1.0.0-rc.7";A.vnode=w;"undefined"!==typeof module?module.exports=A:window.m=A};
|
||||
|
|
@ -33,7 +33,7 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
return args
|
||||
}
|
||||
|
||||
|
||||
function request(args, extra) {
|
||||
var finalize = finalizer()
|
||||
args = normalize(args, extra)
|
||||
|
|
@ -63,6 +63,10 @@ module.exports = function($window, Promise) {
|
|||
}
|
||||
if (args.withCredentials) xhr.withCredentials = args.withCredentials
|
||||
|
||||
for (var key in args.headers) if ({}.hasOwnProperty.call(args.headers, key)) {
|
||||
xhr.setRequestHeader(key, args.headers[key])
|
||||
}
|
||||
|
||||
if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
|
|
@ -93,7 +97,7 @@ module.exports = function($window, Promise) {
|
|||
function jsonp(args, extra) {
|
||||
var finalize = finalizer()
|
||||
args = normalize(args, extra)
|
||||
|
||||
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
var callbackName = args.callbackName || "_mithril_" + Math.round(Math.random() * 1e16) + "_" + callbackCount++
|
||||
var script = $window.document.createElement("script")
|
||||
|
|
|
|||
|
|
@ -343,6 +343,43 @@ o.spec("xhr", function() {
|
|||
done()
|
||||
}, 20)
|
||||
})
|
||||
o("headers are set when header arg passed", function(done) {
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: ""}
|
||||
}
|
||||
})
|
||||
xhr({method: "POST", url: "/item", config: config, headers: {"Custom-Header": "Value"}}).then(done)
|
||||
|
||||
function config(xhr) {
|
||||
o(xhr.getRequestHeader("Custom-Header")).equals("Value")
|
||||
}
|
||||
})
|
||||
o("headers are with higher precedence than default headers", function(done) {
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: ""}
|
||||
}
|
||||
})
|
||||
xhr({method: "POST", url: "/item", config: config, headers: {"Content-Type": "Value"}}).then(done)
|
||||
|
||||
function config(xhr) {
|
||||
o(xhr.getRequestHeader("Content-Type")).equals("Value")
|
||||
}
|
||||
})
|
||||
o("json headers are set to the correct default value", function(done) {
|
||||
mock.$defineRoutes({
|
||||
"POST /item": function(request) {
|
||||
return {status: 200, responseText: ""}
|
||||
}
|
||||
})
|
||||
xhr({method: "POST", url: "/item", config: config}).then(done)
|
||||
|
||||
function config(xhr) {
|
||||
o(xhr.getRequestHeader("Content-Type")).equals("application/json; charset=utf-8")
|
||||
o(xhr.getRequestHeader("Accept")).equals("application/json, text/*")
|
||||
}
|
||||
})
|
||||
})
|
||||
o.spec("failure", function() {
|
||||
o("rejects on server error", function(done) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,13 @@ module.exports = function() {
|
|||
var $window = {
|
||||
XMLHttpRequest: function XMLHttpRequest() {
|
||||
var args = {}
|
||||
this.setRequestHeader = function(header, value) {}
|
||||
var headers = {}
|
||||
this.setRequestHeader = function(header, value) {
|
||||
headers[header] = value
|
||||
}
|
||||
this.getRequestHeader = function(header) {
|
||||
return headers[header]
|
||||
}
|
||||
this.open = function(method, url, async, user, password) {
|
||||
var urlData = parseURL(url, {protocol: "http:", hostname: "localhost", port: "", pathname: "/"})
|
||||
args.method = method
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue