mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-09 00:08:18 +08:00
c23ba31e17
Thread dropdown Small fixes
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
|
|
var isPromise = function (value) {
|
|
return value && typeof value.then === "function";
|
|
};
|
|
|
|
var defer = function () {
|
|
var pending = [], value;
|
|
return {
|
|
resolve: function (_value) {
|
|
if (pending) {
|
|
value = ref(_value);
|
|
for (var i = 0, ii = pending.length; i < ii; i++) {
|
|
// apply the pending arguments to "then"
|
|
value.then.apply(value, pending[i]);
|
|
}
|
|
pending = undefined;
|
|
}
|
|
},
|
|
promise: {
|
|
then: function (_callback, _errback) {
|
|
var result = defer();
|
|
var callback = function (value) {
|
|
result.resolve(_callback(value));
|
|
};
|
|
var errback = function (reason) {
|
|
result.resolve(_errback(reason));
|
|
};
|
|
if (pending) {
|
|
pending.push([callback, errback]);
|
|
} else {
|
|
value.then(callback, errback);
|
|
}
|
|
return result.promise;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
var ref = function (value) {
|
|
if (value && typeof value.then === "function")
|
|
return value;
|
|
return {
|
|
then: function (callback) {
|
|
return ref(callback(value));
|
|
}
|
|
};
|
|
};
|
|
|
|
var reject = function (reason) {
|
|
return {
|
|
then: function (callback, errback) {
|
|
return ref(errback(reason));
|
|
}
|
|
};
|
|
};
|
|
|