diff --git a/docs/api.md b/docs/api.md index 9dd92e8c..9b301bdb 100644 --- a/docs/api.md +++ b/docs/api.md @@ -18,4 +18,5 @@ - [m.redraw](redraw.md) - [m.version](version.md) -- [stream](stream.md) \ No newline at end of file +- [Promise](promise.md) +- [Stream](stream.md) \ No newline at end of file diff --git a/docs/v1.x-migration.md b/docs/v1.x-migration.md index 502ef3a9..f23111b1 100644 --- a/docs/v1.x-migration.md +++ b/docs/v1.x-migration.md @@ -441,7 +441,7 @@ setTimeout(function() { }, 1000) ``` -The equivalent of `m.sync` is now `m.Promise.all` +The equivalent of `m.sync` is now `Promise.all` ### `v0.2.x` @@ -458,7 +458,7 @@ m.sync([ ### `v1.x` ```javascript -m.Promise.all([ +Promise.all([ m.request({ method: 'GET', url: 'https://api.github.com/users/lhorie' }), m.request({ method: 'GET', url: 'https://api.github.com/users/isiahmeadows' }), ]) diff --git a/index.js b/index.js index 8e4917ad..8ae9df25 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,6 @@ var redrawService = require("./redraw") requestService.setCompletionCallback(redrawService.publish) -m.Promise = require("./promise/promise") m.mount = require("./mount") m.route = require("./route") m.withAttr = require("./util/withAttr") diff --git a/mithril.js b/mithril.js index e8a90fad..38fe365d 100644 --- a/mithril.js +++ b/mithril.js @@ -173,6 +173,10 @@ PromisePolyfill0.race = function(list) { } }) } +if (typeof Promise === "undefined") { + if (typeof window !== "undefined") window.Promise = PromisePolyfill0 + else if (typeof global !== "undefined") global.Promise = PromisePolyfill0 +} var PromisePolyfill = typeof Promise !== "undefined" ? Promise : PromisePolyfill0 var buildQueryString = function(object) { if (Object.prototype.toString.call(object) !== "[object Object]") return "" @@ -337,8 +341,7 @@ var _11 = function() { } var redrawService = _11() requestService.setCompletionCallback(redrawService.publish) -m.Promise = PromisePolyfill -var _14 = function($window) { +var _13 = function($window) { var $doc = $window.document var $emptyFragment = $doc.createDocumentFragment() var onevent @@ -873,7 +876,7 @@ var _14 = function($window) { } return {render: render, setEventCallback: setEventCallback} } -var renderService = _14(window) +var renderService = _13(window) var throttle = function(callback1) { //60fps translates to 16.6ms, round it down since setTimeout requires int var time = 16 @@ -907,7 +910,7 @@ var autoredraw = function(root, renderer, pubsub, callback0) { } return root.redraw = run1 } -var _18 = function(renderer, pubsub) { +var _17 = function(renderer, pubsub) { return function(root, component) { if (component === null) { renderer.render(root, []) @@ -923,7 +926,7 @@ var _18 = function(renderer, pubsub) { run0() } } -m.mount = _18(renderService, redrawService) +m.mount = _17(renderService, redrawService) var mount = m.mount var parseQueryString = function(string) { if (string === "" || string == null) return {} @@ -1060,7 +1063,7 @@ var coreRouter = function($window) { } return {setPrefix: setPrefix, getPath: getPath, setPath: setPath, defineRoutes: defineRoutes, link: link} } -var _24 = function($window, mount0) { +var _23 = function($window, mount0) { var router = coreRouter($window) var currentResolve, currentComponent, currentRender, currentArgs, currentPath var RouteComponent = {view: function() { @@ -1105,7 +1108,7 @@ var _24 = function($window, mount0) { route.get = function() {return currentPath} return route } -m.route = _24(window, mount) +m.route = _23(window, mount) m.withAttr = function(attrName, callback2, context) { return function(e) { return callback2.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName)) diff --git a/mithril.min.js b/mithril.min.js index 629dd000..6938252a 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,40 +1,40 @@ -new function(){function m(a,b,k,d,l,h){return{tag:a,key:b,attrs:k,children:d,text:l,dom:h,domSize:void 0,state:{},events:void 0,instance:void 0,skip:!1}}function t(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===H[a]){for(var b,k,d=[],l={};b=N.exec(a);){var h=b[1],u=b[2];""===h&&""!==u?k=u:"#"===h?l.id=u:"."===h?d.push(u):"["===b[3][0]&&((h=b[6])&&(h=h.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")), -l[b[4]]=h||!0)}0a.indexOf("?")?"?":"&";a+=d+f}return a}function u(a){try{return""!==a?JSON.parse(a):null}catch(w){throw Error(a);}}function q(a){return a.responseText} -function r(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;dp.status||304===p.status)b(r(f.type,a));else{var h=Error(p.responseText),k;for(k in a)h[k]=a[k];d(h)}}catch(G){d(G)}};n&&null!=f.data?p.send(f.data):p.send()}))},jsonp:function(f){return d(new b(function(b,d){var p=f.callbackName||"_mithril_"+Math.round(1E16* -Math.random())+"_"+m++,k=a.document.createElement("script");a[p]=function(d){k.parentNode.removeChild(k);b(r(f.type,d));delete a[p]};k.onerror=function(){k.parentNode.removeChild(k);d(Error("JSONP request failed"));delete a[p]};null==f.data&&(f.data={});f.url=l(f.url,f.data);f.data[f.callbackKey||"callback"]=p;k.src=h(f.url,f.data);a.document.documentElement.appendChild(k)}))},setCompletionCallback:function(a){v=a}}}(window,C),K=function(){var a=[];return{subscribe:a.push.bind(a),unsubscribe:function(b){b= -a.indexOf(b);-1=l&&B>=A;){var x=a[l],m=e[A];if(x!==m||g)if(null!=x&&null!=m&&x.key===m.key)l++,A++,h(c,x,m,f,q(a,l,d),g,p),g&&x.tag===m.tag&&r(c,u(x),d);else if(x=a[v],x!==m||g)if(null!=x&&null!=m&&x.key===m.key)h(c,x,m,f,q(a,v+1,d),g,p),(g||A=l&&B>=A;){x=a[v];m=e[B];if(x!==m||g)if(null!=x&&null!=m&&x.key===m.key)h(c,x,m,f,q(a,v+1,d),g,p),g&&x.tag===m.tag&&r(c,u(x),d),null!=x.dom&&(d=x.dom),v--;else{if(!w){w=a;var x=v,D={},t;for(t=0;ta.indexOf("?")?"?":"&";a+=d+f}return a}function u(a){try{return""!== +a?JSON.parse(a):null}catch(w){throw Error(a);}}function q(a){return a.responseText}function r(a,b){if("function"===typeof a)if(b instanceof Array)for(var d=0;dp.status||304===p.status)b(r(f.type,a));else{var h=Error(p.responseText),k;for(k in a)h[k]=a[k];d(h)}}catch(F){d(F)}};n&&null!=f.data?p.send(f.data):p.send()}))}, +jsonp:function(f){return d(new b(function(b,d){var p=f.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,k=a.document.createElement("script");a[p]=function(d){k.parentNode.removeChild(k);b(r(f.type,d));delete a[p]};k.onerror=function(){k.parentNode.removeChild(k);d(Error("JSONP request failed"));delete a[p]};null==f.data&&(f.data={});f.url=l(f.url,f.data);f.data[f.callbackKey||"callback"]=p;k.src=h(f.url,f.data);a.document.documentElement.appendChild(k)}))},setCompletionCallback:function(a){v= +a}}}(window,"undefined"!==typeof Promise?Promise:x),I=function(){var a=[];return{subscribe:a.push.bind(a),unsubscribe:function(b){b=a.indexOf(b);-1=l&&B>=z;){var y=a[l],m=e[z];if(y!==m||g)if(null!=y&&null!=m&&y.key===m.key)l++,z++,h(c,y,m,f,q(a,l,d),g, +p),g&&y.tag===m.tag&&r(c,u(y),d);else if(y=a[v],y!==m||g)if(null!=y&&null!=m&&y.key===m.key)h(c,y,m,f,q(a,v+1,d),g,p),(g||z=l&&B>=z;){y=a[v];m=e[B];if(y!==m||g)if(null!=y&&null!=m&&y.key===m.key)h(c,y,m,f,q(a,v+1,d),g,p),g&&y.tag===m.tag&&r(c,u(y),d),null!=y.dom&&(d=y.dom),v--;else{if(!w){w=a;var y=v,D={},t;for(t=0;t