From c27579181dae11001b987bb072e243c453b01874 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sat, 27 Jun 2015 06:58:15 -0400 Subject: [PATCH] feature(bower) promise-poyfill v2.1.0 --- bower.json | 4 ++-- modules/promise-polyfill/.bower.json | 13 +++++++------ modules/promise-polyfill/Promise.js | 24 ++++++++++++++---------- modules/promise-polyfill/Promise.min.js | 4 ++-- modules/promise-polyfill/README.md | 12 ++++++++++-- modules/promise-polyfill/bower.json | 2 +- modules/promise-polyfill/jasmine.json | 7 +++++++ modules/promise-polyfill/package.json | 16 +++++++++++----- 8 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 modules/promise-polyfill/jasmine.json diff --git a/bower.json b/bower.json index 09daa66b..0954f90f 100644 --- a/bower.json +++ b/bower.json @@ -24,11 +24,11 @@ "fancybox": "~2.1.5", "jquery": "~2.1.4", "menu": "~0.7.8", - "promise-polyfill": "~2.0.0", "format-io": "~0.9.6", "rendy": "~1.1.0", "github": "~0.10.6", "vk-openapi": "~0.0.1", - "domtokenlist-shim": "~1.1.0" + "domtokenlist-shim": "~1.1.0", + "promise-polyfill": "~2.1.0" } } diff --git a/modules/promise-polyfill/.bower.json b/modules/promise-polyfill/.bower.json index 7128614d..63cbef81 100644 --- a/modules/promise-polyfill/.bower.json +++ b/modules/promise-polyfill/.bower.json @@ -1,6 +1,6 @@ { "name": "promise-polyfill", - "version": "2.0.0", + "version": "2.1.0", "homepage": "https://github.com/taylorhakes/promise-polyfill", "authors": [ "Taylor Hakes" @@ -25,13 +25,14 @@ "test", "tests" ], - "_release": "2.0.0", + "_release": "2.1.0", "_resolution": { "type": "version", - "tag": "2.0.0", - "commit": "970996440115e6c5ec0dc84a15e00fc04b34651f" + "tag": "2.1.0", + "commit": "7ee8e28671e2e7ff0304ea37c3d1fb1288645362" }, "_source": "git://github.com/taylorhakes/promise-polyfill.git", - "_target": "~2.0.0", - "_originalSource": "promise-polyfill" + "_target": "~2.1.0", + "_originalSource": "promise-polyfill", + "_direct": true } \ No newline at end of file diff --git a/modules/promise-polyfill/Promise.js b/modules/promise-polyfill/Promise.js index 9c55485b..47453e50 100644 --- a/modules/promise-polyfill/Promise.js +++ b/modules/promise-polyfill/Promise.js @@ -1,14 +1,8 @@ -(function() { - var root; - - if (typeof window === 'object' && window) { - root = window; - } else { - root = global; - } +(function(root) { // Use polyfill for setImmediate for performance gains - var asap = Promise.immediateFn || root.setImmediate || function(fn) { setTimeout(fn, 1); }; + var asap = (typeof setImmediate === 'function' && setImmediate) || + function(fn) { setTimeout(fn, 1); }; // Polyfill for Function.prototype.bind function bind(fn, thisArg) { @@ -178,9 +172,19 @@ }); }; + /** + * Set the immediate function to execute callbacks + * @param fn {function} Function to execute + * @private + */ + Promise._setImmediateFn = function _setImmediateFn(fn) { + asap = fn; + }; + if (typeof module !== 'undefined' && module.exports) { module.exports = Promise; } else if (!root.Promise) { root.Promise = Promise; } -})(); \ No newline at end of file + +})(this); \ No newline at end of file diff --git a/modules/promise-polyfill/Promise.min.js b/modules/promise-polyfill/Promise.min.js index f3ee36e6..fe61cac6 100644 --- a/modules/promise-polyfill/Promise.min.js +++ b/modules/promise-polyfill/Promise.min.js @@ -1,2 +1,2 @@ -/*! promise-polyfill 2.0.0 */ -!function(){function a(a,b){return function(){a.apply(b,arguments)}}function b(b){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof b)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],h(b,a(d,this),a(e,this))}function c(a){var b=this;return null===this._state?void this._deferreds.push(a):void j(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var d;try{d=c(b._value)}catch(e){return void a.reject(e)}a.resolve(d)})}function d(b){try{if(b===this)throw new TypeError("A promise cannot be resolved with itself.");if(b&&("object"==typeof b||"function"==typeof b)){var c=b.then;if("function"==typeof c)return void h(a(c,b),a(d,this),a(e,this))}this._state=!0,this._value=b,f.call(this)}catch(g){e.call(this,g)}}function e(a){this._state=!1,this._value=a,f.call(this)}function f(){for(var a=0,b=this._deferreds.length;b>a;a++)c.call(this,this._deferreds[a]);this._deferreds=null}function g(a,b,c,d){this.onFulfilled="function"==typeof a?a:null,this.onRejected="function"==typeof b?b:null,this.resolve=c,this.reject=d}function h(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(e){if(d)return;d=!0,c(e)}}var i;i="object"==typeof window&&window?window:global;var j=b.immediateFn||i.setImmediate||function(a){setTimeout(a,1)},k=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};b.prototype["catch"]=function(a){return this.then(null,a)},b.prototype.then=function(a,d){var e=this;return new b(function(b,f){c.call(e,new g(a,d,b,f))})},b.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&k(arguments[0])?arguments[0]:arguments);return new b(function(b,c){function d(f,g){try{if(g&&("object"==typeof g||"function"==typeof g)){var h=g.then;if("function"==typeof h)return void h.call(g,function(a){d(f,a)},c)}a[f]=g,0===--e&&b(a)}catch(i){c(i)}}if(0===a.length)return b([]);for(var e=a.length,f=0;fd;d++)a[d].then(b,c)})},"undefined"!=typeof module&&module.exports?module.exports=b:i.Promise||(i.Promise=b)}(); \ No newline at end of file +/*! promise-polyfill 2.1.0 */ +!function(a){function b(a,b){return function(){a.apply(b,arguments)}}function c(a){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof a)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],i(a,b(e,this),b(f,this))}function d(a){var b=this;return null===this._state?void this._deferreds.push(a):void j(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var d;try{d=c(b._value)}catch(e){return void a.reject(e)}a.resolve(d)})}function e(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"==typeof a||"function"==typeof a)){var c=a.then;if("function"==typeof c)return void i(b(c,a),b(e,this),b(f,this))}this._state=!0,this._value=a,g.call(this)}catch(d){f.call(this,d)}}function f(a){this._state=!1,this._value=a,g.call(this)}function g(){for(var a=0,b=this._deferreds.length;b>a;a++)d.call(this,this._deferreds[a]);this._deferreds=null}function h(a,b,c,d){this.onFulfilled="function"==typeof a?a:null,this.onRejected="function"==typeof b?b:null,this.resolve=c,this.reject=d}function i(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(e){if(d)return;d=!0,c(e)}}var j="function"==typeof setImmediate&&setImmediate||function(a){setTimeout(a,1)},k=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};c.prototype["catch"]=function(a){return this.then(null,a)},c.prototype.then=function(a,b){var e=this;return new c(function(c,f){d.call(e,new h(a,b,c,f))})},c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&k(arguments[0])?arguments[0]:arguments);return new c(function(b,c){function d(f,g){try{if(g&&("object"==typeof g||"function"==typeof g)){var h=g.then;if("function"==typeof h)return void h.call(g,function(a){d(f,a)},c)}a[f]=g,0===--e&&b(a)}catch(i){c(i)}}if(0===a.length)return b([]);for(var e=a.length,f=0;fd;d++)a[d].then(b,c)})},c._setImmediateFn=function(a){j=a},"undefined"!=typeof module&&module.exports?module.exports=c:a.Promise||(a.Promise=c)}(this); \ No newline at end of file diff --git a/modules/promise-polyfill/README.md b/modules/promise-polyfill/README.md index 627946d3..41c8b9c6 100644 --- a/modules/promise-polyfill/README.md +++ b/modules/promise-polyfill/README.md @@ -13,6 +13,9 @@ For API information about Promises, please check out this article [HTML5Rocks ar It is extremely lightweight. ***< 1kb Gzipped*** +## Browser Support +IE8+, Chrome, Firefox, IOS 4+, Safari 5+, Opera + ## Downloads - [Promise](https://raw.github.com/taylorhakes/promise-polyfill/master/Promise.js) @@ -22,6 +25,10 @@ It is extremely lightweight. ***< 1kb Gzipped*** ``` npm install promise-polyfill ``` +### Bower +``` +bower install promise-polyfill +``` ## Simple use ``` @@ -30,8 +37,7 @@ var prom = new Promise(function(resolve, reject) { if (/* everything turned out fine */) { resolve("Stuff worked!"); - } - else { + } else { reject(new Error("It broke")); } }); @@ -45,6 +51,8 @@ prom.then(function() { By default promise-polyfill uses `setImmediate`, but falls back to `setTimeout` for executing asynchronously. If a browser does not support `setImmediate`, you may see performance issues. Use a `setImmediate` polyfill to fix this issue. [setAsap](https://github.com/taylorhakes/setAsap) or [setImmediate](https://github.com/YuzuJS/setImmediate) work well. +If you polyfill `window.setImmediate` or use `Promise._setImmediateFn(immedateFn)` it will be used instead of `window.setTimeout` + ## Testing ``` npm install diff --git a/modules/promise-polyfill/bower.json b/modules/promise-polyfill/bower.json index 8ee7394d..d7c12b6c 100644 --- a/modules/promise-polyfill/bower.json +++ b/modules/promise-polyfill/bower.json @@ -1,6 +1,6 @@ { "name": "promise-polyfill", - "version": "1.1.4", + "version": "2.1.0", "homepage": "https://github.com/taylorhakes/promise-polyfill", "authors": [ "Taylor Hakes" diff --git a/modules/promise-polyfill/jasmine.json b/modules/promise-polyfill/jasmine.json new file mode 100644 index 00000000..9f4542e6 --- /dev/null +++ b/modules/promise-polyfill/jasmine.json @@ -0,0 +1,7 @@ +{ + "spec_dir": "tests", + "spec_files": [ + "**/*.spec.js" + ], + "helpers": [] +} \ No newline at end of file diff --git a/modules/promise-polyfill/package.json b/modules/promise-polyfill/package.json index 75afee05..8817f83d 100644 --- a/modules/promise-polyfill/package.json +++ b/modules/promise-polyfill/package.json @@ -1,10 +1,10 @@ { "name": "promise-polyfill", - "version": "2.0.0", + "version": "2.1.0", "description": "Lightweight promise polyfill. A+ compliant", "main": "Promise.js", "scripts": { - "test": "./node_modules/.bin/promises-aplus-tests tests/adapter.js" + "test": "./node_modules/.bin/promises-aplus-tests tests/adapter.js && JASMINE_CONFIG_PATH=jasmine.json ./node_modules/jasmine/bin/jasmine.js;" }, "repository": { "type": "git", @@ -17,10 +17,16 @@ }, "homepage": "https://github.com/taylorhakes/promise-polyfill", "devDependencies": { - "promises-aplus-tests": "*", "grunt": "^0.4.4", - "grunt-contrib-uglify": "^0.4.0" + "grunt-contrib-uglify": "^0.4.0", + "jasmine": "^2.3.1", + "promises-aplus-tests": "*" }, - "keywords": ["promise", "promise-polyfill", "ES6", "promises-aplus"], + "keywords": [ + "promise", + "promise-polyfill", + "ES6", + "promises-aplus" + ], "dependencies": {} }