mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-09 01:17:04 +03:00
Improve scripts load system
This commit is contained in:
parent
58b9eed8e8
commit
72bf212f67
39 changed files with 916 additions and 411 deletions
2
vendors/es6-promise-polyfill/.gitignore
vendored
Normal file
2
vendors/es6-promise-polyfill/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/node_modules
|
||||
/tmp
|
||||
3
vendors/es6-promise-polyfill/.npmignore
vendored
Normal file
3
vendors/es6-promise-polyfill/.npmignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/node_modules/
|
||||
/tmp
|
||||
/test
|
||||
6
vendors/es6-promise-polyfill/.travis.yml
vendored
Normal file
6
vendors/es6-promise-polyfill/.travis.yml
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "node"
|
||||
- "iojs"
|
||||
18
vendors/es6-promise-polyfill/CHANGELOG.md
vendored
Normal file
18
vendors/es6-promise-polyfill/CHANGELOG.md
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
## 1.2.0 (December 8, 2015)
|
||||
|
||||
- Support for IE8 and below
|
||||
- Promises/A+ tests added
|
||||
|
||||
## 1.1.0 (October 16, 2015)
|
||||
|
||||
- Change way to get reference to `global`, since `Function()()` may be prohibited
|
||||
- Add AMD support
|
||||
|
||||
## 1.0.1 (September 14, 2015)
|
||||
|
||||
- Fix exports - use polyfill only if native implementation isn't supported
|
||||
- Add license
|
||||
|
||||
## 1.0.0 (June 19, 2014)
|
||||
|
||||
- Init release
|
||||
22
vendors/es6-promise-polyfill/LICENSE
vendored
Normal file
22
vendors/es6-promise-polyfill/LICENSE
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 Roman Dvornov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
88
vendors/es6-promise-polyfill/README.md
vendored
Normal file
88
vendors/es6-promise-polyfill/README.md
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
[](https://www.npmjs.com/package/es6-promise-polyfill)
|
||||
[](https://travis-ci.org/lahmatiy/es6-promise-polyfill)
|
||||
|
||||
# ES6 Promise polyfill
|
||||
|
||||
This is a polyfill of [ES6 Promise](https://github.com/domenic/promises-unwrapping). The implementation based on [Jake Archibald implementation](https://github.com/jakearchibald/es6-promise) a subset of [rsvp.js](https://github.com/tildeio/rsvp.js). If you're wanting extra features and more debugging options, check out the [full library](https://github.com/tildeio/rsvp.js).
|
||||
|
||||
For API details and how to use promises, see the <a href="http://www.html5rocks.com/en/tutorials/es6/promises/">JavaScript Promises HTML5Rocks article</a>.
|
||||
|
||||
## Notes
|
||||
|
||||
The main target: implementation should be conformance with browser's implementations and to be minimal as possible in size. So it's strictly polyfill of ES6 Promise specification and nothing more.
|
||||
|
||||
It passes both [Promises/A+ test suite](https://github.com/promises-aplus/promises-tests) and [rsvp.js test suite](https://github.com/jakearchibald/es6-promise/tree/master/test). And as small as 2,6KB min (or 1KB min+gzip).
|
||||
|
||||
The polyfill uses `setImmediate` if available, or fallback to use `setTimeout`. Use [setImmediate polyfill](https://github.com/YuzuJS/setImmediate) by @YuzuJS to reach better performance.
|
||||
|
||||
## How to use
|
||||
|
||||
### Browser
|
||||
|
||||
To install:
|
||||
|
||||
```sh
|
||||
bower install es6-promise-polyfill
|
||||
```
|
||||
|
||||
To use:
|
||||
|
||||
```html
|
||||
<script src="bower_components/es6-promise-polyfill/promise.min.js"></script>
|
||||
<script>
|
||||
var promise = new Promise(...);
|
||||
</script>
|
||||
```
|
||||
|
||||
### Node.js
|
||||
|
||||
To install:
|
||||
|
||||
```sh
|
||||
npm install es6-promise-polyfill
|
||||
```
|
||||
|
||||
To use:
|
||||
|
||||
```js
|
||||
var Promise = require('es6-promise-polyfill').Promise;
|
||||
var promise = new Promise(...);
|
||||
```
|
||||
|
||||
### AMD
|
||||
|
||||
To install:
|
||||
|
||||
```sh
|
||||
npm install es6-promise-polyfill
|
||||
```
|
||||
|
||||
To use:
|
||||
|
||||
```js
|
||||
define(['es6-promise-polyfill'], function(Promise) {
|
||||
var promise = new Promise(...);
|
||||
});
|
||||
```
|
||||
|
||||
## Usage in IE<9
|
||||
|
||||
`catch` is a reserved word in IE<9, meaning `promise.catch(func)` throws a syntax error. To work around this, use a string to access the property:
|
||||
|
||||
```js
|
||||
promise['catch'](function(err) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
Or use `.then` instead:
|
||||
|
||||
```js
|
||||
promise.then(undefined, function(err) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Licensed under the MIT License.
|
||||
11
vendors/es6-promise-polyfill/bower.json
vendored
Normal file
11
vendors/es6-promise-polyfill/bower.json
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "es6-promise-polyfill",
|
||||
"version": "1.1.1",
|
||||
"main": "promise.js",
|
||||
"ignore": [
|
||||
".*",
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
27
vendors/es6-promise-polyfill/package.json
vendored
Normal file
27
vendors/es6-promise-polyfill/package.json
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "es6-promise-polyfill",
|
||||
"description": "Polyfill for ES6 Promise",
|
||||
"version": "1.2.0",
|
||||
"author": "Roman Dvornov <rdvornov@gmail.com>",
|
||||
"license": "MIT",
|
||||
"repository": "lahmatiy/es6-promise-polyfill",
|
||||
"bugs": {
|
||||
"url": "https://github.com/lahmatiy/es6-promise-polyfill/issues"
|
||||
},
|
||||
"main": "promise.js",
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"promises-aplus-tests": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "promises-aplus-tests test/test-adapter"
|
||||
},
|
||||
"keywords": [
|
||||
"es6",
|
||||
"es2015",
|
||||
"polyfill",
|
||||
"promise",
|
||||
"promises"
|
||||
]
|
||||
}
|
||||
346
vendors/es6-promise-polyfill/promise.js
vendored
Normal file
346
vendors/es6-promise-polyfill/promise.js
vendored
Normal file
|
|
@ -0,0 +1,346 @@
|
|||
(function(global){
|
||||
|
||||
//
|
||||
// Check for native Promise and it has correct interface
|
||||
//
|
||||
|
||||
var NativePromise = global['Promise'];
|
||||
var nativePromiseSupported =
|
||||
NativePromise &&
|
||||
// Some of these methods are missing from
|
||||
// Firefox/Chrome experimental implementations
|
||||
'resolve' in NativePromise &&
|
||||
'reject' in NativePromise &&
|
||||
'all' in NativePromise &&
|
||||
'race' in NativePromise &&
|
||||
// Older version of the spec had a resolver object
|
||||
// as the arg rather than a function
|
||||
(function(){
|
||||
var resolve;
|
||||
new NativePromise(function(r){ resolve = r; });
|
||||
return typeof resolve === 'function';
|
||||
})();
|
||||
|
||||
|
||||
//
|
||||
// export if necessary
|
||||
//
|
||||
|
||||
if (typeof exports !== 'undefined' && exports)
|
||||
{
|
||||
// node.js
|
||||
exports.Promise = nativePromiseSupported ? NativePromise : Promise;
|
||||
exports.Polyfill = Promise;
|
||||
}
|
||||
else
|
||||
{
|
||||
// AMD
|
||||
if (typeof define == 'function' && define.amd)
|
||||
{
|
||||
define(function(){
|
||||
return nativePromiseSupported ? NativePromise : Promise;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// in browser add to global
|
||||
if (!nativePromiseSupported)
|
||||
global['Promise'] = Promise;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Polyfill
|
||||
//
|
||||
|
||||
var PENDING = 'pending';
|
||||
var SEALED = 'sealed';
|
||||
var FULFILLED = 'fulfilled';
|
||||
var REJECTED = 'rejected';
|
||||
var NOOP = function(){};
|
||||
|
||||
function isArray(value) {
|
||||
return Object.prototype.toString.call(value) === '[object Array]';
|
||||
}
|
||||
|
||||
// async calls
|
||||
var asyncSetTimer = typeof setImmediate !== 'undefined' ? setImmediate : setTimeout;
|
||||
var asyncQueue = [];
|
||||
var asyncTimer;
|
||||
|
||||
function asyncFlush(){
|
||||
// run promise callbacks
|
||||
for (var i = 0; i < asyncQueue.length; i++)
|
||||
asyncQueue[i][0](asyncQueue[i][1]);
|
||||
|
||||
// reset async asyncQueue
|
||||
asyncQueue = [];
|
||||
asyncTimer = false;
|
||||
}
|
||||
|
||||
function asyncCall(callback, arg){
|
||||
asyncQueue.push([callback, arg]);
|
||||
|
||||
if (!asyncTimer)
|
||||
{
|
||||
asyncTimer = true;
|
||||
asyncSetTimer(asyncFlush, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function invokeResolver(resolver, promise) {
|
||||
function resolvePromise(value) {
|
||||
resolve(promise, value);
|
||||
}
|
||||
|
||||
function rejectPromise(reason) {
|
||||
reject(promise, reason);
|
||||
}
|
||||
|
||||
try {
|
||||
resolver(resolvePromise, rejectPromise);
|
||||
} catch(e) {
|
||||
rejectPromise(e);
|
||||
}
|
||||
}
|
||||
|
||||
function invokeCallback(subscriber){
|
||||
var owner = subscriber.owner;
|
||||
var settled = owner.state_;
|
||||
var value = owner.data_;
|
||||
var callback = subscriber[settled];
|
||||
var promise = subscriber.then;
|
||||
|
||||
if (typeof callback === 'function')
|
||||
{
|
||||
settled = FULFILLED;
|
||||
try {
|
||||
value = callback(value);
|
||||
} catch(e) {
|
||||
reject(promise, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!handleThenable(promise, value))
|
||||
{
|
||||
if (settled === FULFILLED)
|
||||
resolve(promise, value);
|
||||
|
||||
if (settled === REJECTED)
|
||||
reject(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
function handleThenable(promise, value) {
|
||||
var resolved;
|
||||
|
||||
try {
|
||||
if (promise === value)
|
||||
throw new TypeError('A promises callback cannot return that same promise.');
|
||||
|
||||
if (value && (typeof value === 'function' || typeof value === 'object'))
|
||||
{
|
||||
var then = value.then; // then should be retrived only once
|
||||
|
||||
if (typeof then === 'function')
|
||||
{
|
||||
then.call(value, function(val){
|
||||
if (!resolved)
|
||||
{
|
||||
resolved = true;
|
||||
|
||||
if (value !== val)
|
||||
resolve(promise, val);
|
||||
else
|
||||
fulfill(promise, val);
|
||||
}
|
||||
}, function(reason){
|
||||
if (!resolved)
|
||||
{
|
||||
resolved = true;
|
||||
|
||||
reject(promise, reason);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (!resolved)
|
||||
reject(promise, e);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function resolve(promise, value){
|
||||
if (promise === value || !handleThenable(promise, value))
|
||||
fulfill(promise, value);
|
||||
}
|
||||
|
||||
function fulfill(promise, value){
|
||||
if (promise.state_ === PENDING)
|
||||
{
|
||||
promise.state_ = SEALED;
|
||||
promise.data_ = value;
|
||||
|
||||
asyncCall(publishFulfillment, promise);
|
||||
}
|
||||
}
|
||||
|
||||
function reject(promise, reason){
|
||||
if (promise.state_ === PENDING)
|
||||
{
|
||||
promise.state_ = SEALED;
|
||||
promise.data_ = reason;
|
||||
|
||||
asyncCall(publishRejection, promise);
|
||||
}
|
||||
}
|
||||
|
||||
function publish(promise) {
|
||||
var callbacks = promise.then_;
|
||||
promise.then_ = undefined;
|
||||
|
||||
for (var i = 0; i < callbacks.length; i++) {
|
||||
invokeCallback(callbacks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function publishFulfillment(promise){
|
||||
promise.state_ = FULFILLED;
|
||||
publish(promise);
|
||||
}
|
||||
|
||||
function publishRejection(promise){
|
||||
promise.state_ = REJECTED;
|
||||
publish(promise);
|
||||
}
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
function Promise(resolver){
|
||||
if (typeof resolver !== 'function')
|
||||
throw new TypeError('Promise constructor takes a function argument');
|
||||
|
||||
if (this instanceof Promise === false)
|
||||
throw new TypeError('Failed to construct \'Promise\': Please use the \'new\' operator, this object constructor cannot be called as a function.');
|
||||
|
||||
this.then_ = [];
|
||||
|
||||
invokeResolver(resolver, this);
|
||||
}
|
||||
|
||||
Promise.prototype = {
|
||||
constructor: Promise,
|
||||
|
||||
state_: PENDING,
|
||||
then_: null,
|
||||
data_: undefined,
|
||||
|
||||
then: function(onFulfillment, onRejection){
|
||||
var subscriber = {
|
||||
owner: this,
|
||||
then: new this.constructor(NOOP),
|
||||
fulfilled: onFulfillment,
|
||||
rejected: onRejection
|
||||
};
|
||||
|
||||
if (this.state_ === FULFILLED || this.state_ === REJECTED)
|
||||
{
|
||||
// already resolved, call callback async
|
||||
asyncCall(invokeCallback, subscriber);
|
||||
}
|
||||
else
|
||||
{
|
||||
// subscribe
|
||||
this.then_.push(subscriber);
|
||||
}
|
||||
|
||||
return subscriber.then;
|
||||
},
|
||||
|
||||
'catch': function(onRejection) {
|
||||
return this.then(null, onRejection);
|
||||
}
|
||||
};
|
||||
|
||||
Promise.all = function(promises){
|
||||
var Class = this;
|
||||
|
||||
if (!isArray(promises))
|
||||
throw new TypeError('You must pass an array to Promise.all().');
|
||||
|
||||
return new Class(function(resolve, reject){
|
||||
var results = [];
|
||||
var remaining = 0;
|
||||
|
||||
function resolver(index){
|
||||
remaining++;
|
||||
return function(value){
|
||||
results[index] = value;
|
||||
if (!--remaining)
|
||||
resolve(results);
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = 0, promise; i < promises.length; i++)
|
||||
{
|
||||
promise = promises[i];
|
||||
|
||||
if (promise && typeof promise.then === 'function')
|
||||
promise.then(resolver(i), reject);
|
||||
else
|
||||
results[i] = promise;
|
||||
}
|
||||
|
||||
if (!remaining)
|
||||
resolve(results);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function(promises){
|
||||
var Class = this;
|
||||
|
||||
if (!isArray(promises))
|
||||
throw new TypeError('You must pass an array to Promise.race().');
|
||||
|
||||
return new Class(function(resolve, reject) {
|
||||
for (var i = 0, promise; i < promises.length; i++)
|
||||
{
|
||||
promise = promises[i];
|
||||
|
||||
if (promise && typeof promise.then === 'function')
|
||||
promise.then(resolve, reject);
|
||||
else
|
||||
resolve(promise);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.resolve = function(value){
|
||||
var Class = this;
|
||||
|
||||
if (value && typeof value === 'object' && value.constructor === Class)
|
||||
return value;
|
||||
|
||||
return new Class(function(resolve){
|
||||
resolve(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function(reason){
|
||||
var Class = this;
|
||||
|
||||
return new Class(function(resolve, reject){
|
||||
reject(reason);
|
||||
});
|
||||
};
|
||||
|
||||
})(typeof window != 'undefined' ? window : typeof global != 'undefined' ? global : typeof self != 'undefined' ? self : this);
|
||||
6
vendors/es6-promise-polyfill/promise.min.js
vendored
Normal file
6
vendors/es6-promise-polyfill/promise.min.js
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(function(t){function z(){for(var a=0;a<g.length;a++)g[a][0](g[a][1]);g=[];m=!1}function n(a,b){g.push([a,b]);m||(m=!0,A(z,0))}function B(a,b){function c(a){p(b,a)}function h(a){k(b,a)}try{a(c,h)}catch(d){h(d)}}function u(a){var b=a.owner,c=b.state_,b=b.data_,h=a[c];a=a.then;if("function"===typeof h){c=l;try{b=h(b)}catch(d){k(a,d)}}v(a,b)||(c===l&&p(a,b),c===q&&k(a,b))}function v(a,b){var c;try{if(a===b)throw new TypeError("A promises callback cannot return that same promise.");if(b&&("function"===
|
||||
typeof b||"object"===typeof b)){var h=b.then;if("function"===typeof h)return h.call(b,function(d){c||(c=!0,b!==d?p(a,d):w(a,d))},function(b){c||(c=!0,k(a,b))}),!0}}catch(d){return c||k(a,d),!0}return!1}function p(a,b){a!==b&&v(a,b)||w(a,b)}function w(a,b){a.state_===r&&(a.state_=x,a.data_=b,n(C,a))}function k(a,b){a.state_===r&&(a.state_=x,a.data_=b,n(D,a))}function y(a){var b=a.then_;a.then_=void 0;for(a=0;a<b.length;a++)u(b[a])}function C(a){a.state_=l;y(a)}function D(a){a.state_=q;y(a)}function e(a){if("function"!==
|
||||
typeof a)throw new TypeError("Promise constructor takes a function argument");if(!1===this instanceof e)throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this.then_=[];B(a,this)}var f=t.Promise,s=f&&"resolve"in f&&"reject"in f&&"all"in f&&"race"in f&&function(){var a;new f(function(b){a=b});return"function"===typeof a}();"undefined"!==typeof exports&&exports?(exports.Promise=s?f:e,exports.Polyfill=e):"function"==
|
||||
typeof define&&define.amd?define(function(){return s?f:e}):s||(t.Promise=e);var r="pending",x="sealed",l="fulfilled",q="rejected",E=function(){},A="undefined"!==typeof setImmediate?setImmediate:setTimeout,g=[],m;e.prototype={constructor:e,state_:r,then_:null,data_:void 0,then:function(a,b){var c={owner:this,then:new this.constructor(E),fulfilled:a,rejected:b};this.state_===l||this.state_===q?n(u,c):this.then_.push(c);return c.then},"catch":function(a){return this.then(null,a)}};e.all=function(a){if("[object Array]"!==
|
||||
Object.prototype.toString.call(a))throw new TypeError("You must pass an array to Promise.all().");return new this(function(b,c){function h(a){e++;return function(c){d[a]=c;--e||b(d)}}for(var d=[],e=0,f=0,g;f<a.length;f++)(g=a[f])&&"function"===typeof g.then?g.then(h(f),c):d[f]=g;e||b(d)})};e.race=function(a){if("[object Array]"!==Object.prototype.toString.call(a))throw new TypeError("You must pass an array to Promise.race().");return new this(function(b,c){for(var e=0,d;e<a.length;e++)(d=a[e])&&"function"===
|
||||
typeof d.then?d.then(b,c):b(d)})};e.resolve=function(a){return a&&"object"===typeof a&&a.constructor===this?a:new this(function(b){b(a)})};e.reject=function(a){return new this(function(b,c){c(a)})}})("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this);
|
||||
22
vendors/es6-promise-polyfill/test/test-adapter.js
vendored
Normal file
22
vendors/es6-promise-polyfill/test/test-adapter.js
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
var assert = require('assert');
|
||||
var Promise = require('../promise').Polyfill;
|
||||
var resolve = Promise.resolve;
|
||||
var reject = Promise.reject;
|
||||
|
||||
function defer(){
|
||||
var deferred = {};
|
||||
|
||||
deferred.promise = new Promise(function(resolve, reject){
|
||||
deferred.resolve = resolve;
|
||||
deferred.reject = reject;
|
||||
});
|
||||
|
||||
return deferred;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
resolved: function(a){ return Promise.resolve(a); },
|
||||
rejected: function(a){ return Promise.reject(a); },
|
||||
deferred: defer,
|
||||
Promise: Promise
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue