diff --git a/mithril.js b/mithril.js index b5d5203c..f4c77a2e 100644 --- a/mithril.js +++ b/mithril.js @@ -82,8 +82,8 @@ hyperscript.fragment = function(attrs1, children) { } var m = hyperscript /** @constructor */ -var PromisePolyfill0 = function(executor) { - if (!(this instanceof PromisePolyfill0)) throw new Error("Promise must be called with `new`") +var PromisePolyfill = function(executor) { + if (!(this instanceof PromisePolyfill)) throw new Error("Promise must be called with `new`") if (typeof executor !== "function") throw new TypeError("executor must be a function") var self = this, resolvers = [], rejectors = [], resolveCurrent = handler(resolvers, true), rejectCurrent = handler(rejectors, false) var instance = self._instance = {resolvers: resolvers, rejectors: rejectors} @@ -124,7 +124,7 @@ var PromisePolyfill0 = function(executor) { } executeOnce(executor) } -PromisePolyfill0.prototype.then = function(onFulfilled, onRejection) { +PromisePolyfill.prototype.then = function(onFulfilled, onRejection) { var self = this, instance = self._instance function handle(callback, list, next, state) { list.push(function(value) { @@ -134,22 +134,22 @@ PromisePolyfill0.prototype.then = function(onFulfilled, onRejection) { if (typeof instance.retry === "function" && state === instance.state) instance.retry() } var resolveNext, rejectNext - var promise = new PromisePolyfill0(function(resolve, reject) {resolveNext = resolve, rejectNext = reject}) + var promise = new PromisePolyfill(function(resolve, reject) {resolveNext = resolve, rejectNext = reject}) handle(onFulfilled, instance.resolvers, resolveNext, true), handle(onRejection, instance.rejectors, rejectNext, false) return promise } -PromisePolyfill0.prototype.catch = function(onRejection) { +PromisePolyfill.prototype.catch = function(onRejection) { return this.then(null, onRejection) } -PromisePolyfill0.resolve = function(value) { - if (value instanceof PromisePolyfill0) return value - return new PromisePolyfill0(function(resolve) {resolve(value)}) +PromisePolyfill.resolve = function(value) { + if (value instanceof PromisePolyfill) return value + return new PromisePolyfill(function(resolve) {resolve(value)}) } -PromisePolyfill0.reject = function(value) { - return new PromisePolyfill0(function(resolve, reject) {reject(value)}) +PromisePolyfill.reject = function(value) { + return new PromisePolyfill(function(resolve, reject) {reject(value)}) } -PromisePolyfill0.all = function(list) { - return new PromisePolyfill0(function(resolve, reject) { +PromisePolyfill.all = function(list) { + return new PromisePolyfill(function(resolve, reject) { var total = list.length, count = 0, values = [] if (list.length === 0) resolve([]) else for (var i = 0; i < list.length; i++) { @@ -167,18 +167,21 @@ PromisePolyfill0.all = function(list) { } }) } -PromisePolyfill0.race = function(list) { - return new PromisePolyfill0(function(resolve, reject) { +PromisePolyfill.race = function(list) { + return new PromisePolyfill(function(resolve, reject) { for (var i = 0; i < list.length; i++) { list[i].then(resolve, reject) } }) } -if (typeof Promise === "undefined") { - if (typeof window !== "undefined") window.Promise = PromisePolyfill0 - else if (typeof global !== "undefined") global.Promise = PromisePolyfill0 +if (typeof window !== "undefined") { + if (typeof window.Promise === "undefined") window.Promise = PromisePolyfill + var PromisePolyfill = window.Promise +} else if (typeof global !== "undefined") { + if (typeof global.Promise === "undefined") global.Promise = PromisePolyfill + var PromisePolyfill = global.Promise +} else { } -var PromisePolyfill = typeof Promise !== "undefined" ? Promise : PromisePolyfill0 var buildQueryString = function(object) { if (Object.prototype.toString.call(object) !== "[object Object]") return "" var args = [] @@ -695,15 +698,6 @@ var coreRenderer = function($window) { } } } - function once(f) { - var called = false - return function() { - if (!called) { - called = true - f() - } - } - } function removeNode(vnode, context) { var expected = 1, called = 0 if (vnode.attrs && vnode.attrs.onbeforeremove) { diff --git a/mithril.min.js b/mithril.min.js index a9424e7a..2034f4f6 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,41 +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===I[a]){for(var c,g,d=[],f={};c=P.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)}0a.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;bm.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?y:u(y)},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, -F),O=function(a){function c(e,h,a,b,c,d,f){for(;a=t&&y>=u;){var x=a[t],n=p[u];if(x!==n||h)if(null==x)t++;else if(null==n)u++;else if(x.key===n.key)t++,u++,k(e,x,n,d,q(a,t,f),h,l),h&&x.tag===n.tag&&m(e,r(x),f);else if(x=a[v],x!==n||h)if(null==x)v--;else if(null==n)u++;else if(x.key===n.key)k(e,x,n,d,q(a,v+1,f),h,l),(h||u=t&&y>=u;){x=a[v];n=p[y];if(x!==n||h)if(null==x)v--;else{if(null!=n)if(x.key===n.key)k(e,x,n,d,q(a,v+1,f),h,l),h&&x.tag===n.tag&&m(e,r(x),f),null!=x.dom&&(f=x.dom),v--;else{if(!C){C=a;var x=v,E={},w;for(w=0;wa.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;bm.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=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=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 -1) return if (pathname.match(/(?:^|\/)tests\/.*\.js$/)) { require(path.normalize(process.cwd()) + "/" + pathname) } diff --git a/promise/promise.js b/promise/promise.js index f24766d1..53aefecc 100644 --- a/promise/promise.js +++ b/promise/promise.js @@ -95,9 +95,12 @@ PromisePolyfill.race = function(list) { }) } -if (typeof Promise === "undefined") { - if (typeof window !== "undefined") window.Promise = PromisePolyfill - else if (typeof global !== "undefined") global.Promise = PromisePolyfill +if (typeof window !== "undefined") { + if (typeof window.Promise === "undefined") window.Promise = PromisePolyfill + module.exports = window.Promise +} else if (typeof global !== "undefined") { + if (typeof global.Promise === "undefined") global.Promise = PromisePolyfill + module.exports = global.Promise +} else { + module.exports = PromisePolyfill } - -module.exports = typeof Promise !== "undefined" ? Promise : PromisePolyfill \ No newline at end of file