diff --git a/README.md b/README.md index 5f5e96acb..20b7f573d 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ mithril.js [](https://ww ## What is Mithril? -A modern client-side Javascript framework for building Single Page Applications. It's small (<!-- size -->8.90 KB<!-- /size --> gzipped), fast and provides routing and XHR utilities out of the box. +A modern client-side Javascript framework for building Single Page Applications. It's small (<!-- size -->8.91 KB<!-- /size --> gzipped), fast and provides routing and XHR utilities out of the box. Mithril is used by companies like Vimeo and Nike, and open source platforms like Lichess 👍. diff --git a/mithril.js b/mithril.js index 6611f9d91..797783b3a 100644 --- a/mithril.js +++ b/mithril.js @@ -389,7 +389,7 @@ var _9 = function($window, Promise) { } function deserialize(data) { try {return data !== "" ? JSON.parse(data) : null} - catch (e) {throw new Error(data)} + catch (e) {throw new Error("Invalid JSON: " + data)} } function extract(xhr) {return xhr.responseText} function cast(type0, data) { diff --git a/mithril.min.js b/mithril.min.js index e8c9051b1..a571c1774 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -8,8 +8,8 @@ d);for(var e=0;e<a.length;e++)a[e](d);q.length=0;h.length=0;m.state=c;m.retry=fu function(d){return p.resolve(a()).then(function(){return p.reject(d)})})};p.resolve=function(a){return a instanceof p?a:new p(function(d){d(a)})};p.reject=function(a){return new p(function(d,e){e(a)})};p.all=function(a){return new p(function(d,e){var g=a.length,q=0,h=[];if(0===a.length)d([]);else for(var k=0;k<a.length;k++)(function(n){function m(a){q++;h[n]=a;q===g&&d(h)}null==a[n]||"object"!==typeof a[n]&&"function"!==typeof a[n]||"function"!==typeof a[n].then?m(a[n]):a[n].then(m,e)})(k)})};p.race= function(a){return new p(function(d,e){for(var g=0;g<a.length;g++)a[g].then(d,e)})};"undefined"!==typeof window?("undefined"===typeof window.Promise?window.Promise=p:window.Promise.prototype["finally"]||(window.Promise.prototype["finally"]=p.prototype["finally"]),p=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise?global.Promise=p:global.Promise.prototype["finally"]||(global.Promise.prototype["finally"]=p.prototype["finally"]),p=global.Promise);var I=function(a){function d(a, g){if(Array.isArray(g))for(var k=0;k<g.length;k++)d(a+"["+k+"]",g[k]);else if("[object Object]"===Object.prototype.toString.call(g))for(k in g)d(a+"["+k+"]",g[k]);else e.push(encodeURIComponent(a)+(null!=g&&""!==g?"="+encodeURIComponent(g):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var e=[],g;for(g in a)d(g,a[g]);return e.join("&")},Z=/^file:\/\//i,O=function(a,d){function e(){function c(){0===--a&&"function"===typeof C&&C()}var a=0;return function F(d){var e=d.then;d.then= -function(){a++;var g=e.apply(d,arguments);g.then(c,function(d){c();if(0===a)throw d;});return F(g)};return d}}function g(c,a){if("string"===typeof c){var d=c;c=a||{};null==c.url&&(c.url=d)}return c}function q(c,a){if(null==a)return c;for(var d=c.match(/:[^\/]+/gi)||[],e=0;e<d.length;e++){var g=d[e].slice(1);null!=a[g]&&(c=c.replace(d[e],a[g]))}return c}function h(c,a){var d=I(a);if(""!==d){var e=0>c.indexOf("?")?"?":"&";c+=e+d}return c}function k(c){try{return""!==c?JSON.parse(c):null}catch(x){throw Error(c); -}}function n(c){return c.responseText}function m(c,a){if("function"===typeof c)if(Array.isArray(a))for(var d=0;d<a.length;d++)a[d]=new c(a[d]);else return new c(a);return a}var l=0,C;return{request:function(c,l){var E=e();c=g(c,l);var x=new d(function(d,e){null==c.method&&(c.method="GET");c.method=c.method.toUpperCase();var g="GET"===c.method||"TRACE"===c.method?!1:"boolean"===typeof c.useBody?c.useBody:!0;"function"!==typeof c.serialize&&(c.serialize="undefined"!==typeof FormData&&c.data instanceof +function(){a++;var g=e.apply(d,arguments);g.then(c,function(d){c();if(0===a)throw d;});return F(g)};return d}}function g(c,a){if("string"===typeof c){var d=c;c=a||{};null==c.url&&(c.url=d)}return c}function q(c,a){if(null==a)return c;for(var d=c.match(/:[^\/]+/gi)||[],e=0;e<d.length;e++){var g=d[e].slice(1);null!=a[g]&&(c=c.replace(d[e],a[g]))}return c}function h(c,a){var d=I(a);if(""!==d){var e=0>c.indexOf("?")?"?":"&";c+=e+d}return c}function k(c){try{return""!==c?JSON.parse(c):null}catch(x){throw Error("Invalid JSON: "+ +c);}}function n(c){return c.responseText}function m(c,a){if("function"===typeof c)if(Array.isArray(a))for(var d=0;d<a.length;d++)a[d]=new c(a[d]);else return new c(a);return a}var l=0,C;return{request:function(c,l){var E=e();c=g(c,l);var x=new d(function(d,e){null==c.method&&(c.method="GET");c.method=c.method.toUpperCase();var g="GET"===c.method||"TRACE"===c.method?!1:"boolean"===typeof c.useBody?c.useBody:!0;"function"!==typeof c.serialize&&(c.serialize="undefined"!==typeof FormData&&c.data instanceof FormData?function(c){return c}:JSON.stringify);"function"!==typeof c.deserialize&&(c.deserialize=k);"function"!==typeof c.extract&&(c.extract=n);c.url=q(c.url,c.data);g?c.data=c.serialize(c.data):c.url=h(c.url,c.data);var l=new a.XMLHttpRequest,E=!1,x=l.abort;l.abort=function(){E=!0;x.call(l)};l.open(c.method,c.url,"boolean"===typeof c.async?c.async:!0,"string"===typeof c.user?c.user:void 0,"string"===typeof c.password?c.password:void 0);c.serialize!==JSON.stringify||!g||c.headers&&c.headers.hasOwnProperty("Content-Type")|| l.setRequestHeader("Content-Type","application/json; charset=utf-8");c.deserialize!==k||c.headers&&c.headers.hasOwnProperty("Accept")||l.setRequestHeader("Accept","application/json, text/*");c.withCredentials&&(l.withCredentials=c.withCredentials);c.timeout&&(l.timeout=c.timeout);for(var C in c.headers)({}).hasOwnProperty.call(c.headers,C)&&l.setRequestHeader(C,c.headers[C]);"function"===typeof c.config&&(l=c.config(l,c)||l);l.onreadystatechange=function(){if(!E&&4===l.readyState)try{var a=c.extract!== n?c.extract(l,c):c.deserialize(c.extract(l,c));if(c.extract!==n||200<=l.status&&300>l.status||304===l.status||Z.test(c.url))d(m(c.type,a));else{var g=Error(l.responseText);g.code=l.status;g.response=a;e(g)}}catch(aa){e(aa)}};g&&null!=c.data?l.send(c.data):l.send()});return!0===c.background?x:E(x)},jsonp:function(c,n){var k=e();c=g(c,n);var x=new d(function(d,e){var g=c.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+l++,n=a.document.createElement("script");a[g]=function(e){n.parentNode.removeChild(n);