igniteui-react-core
Version:
Ignite UI React Core.
100 lines (99 loc) • 3.4 kB
JavaScript
/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
var PromiseWrapper = /** @class */ /*@__PURE__*/ (function () {
function PromiseWrapper(inner) {
var _this = this;
this._state = "pending";
this._resolvedValue = null;
this._rejectedError = null;
this._then = [];
this._fail = [];
this._always = [];
this._promise = inner;
this._promise
.then(function (v) {
_this._state = "resolved";
_this._resolvedValue = v;
for (var i = 0; i < _this._then.length; i++) {
_this._then[i](v);
}
for (var i = 0; i < _this._always.length; i++) {
_this._always[i](v);
}
})
.catch(function (e) {
_this._state = "rejected";
_this._rejectedError = e;
for (var i = 0; i < _this._fail.length; i++) {
_this._fail[i](e);
}
for (var i = 0; i < _this._always.length; i++) {
_this._always[i](e);
}
});
}
PromiseWrapper.prototype.state = function () {
return this._state;
};
PromiseWrapper.prototype.then = function (pass, fail) {
this.done(pass);
this.fail(fail);
return this;
};
PromiseWrapper.prototype.done = function (continuation) {
this._then.push(continuation);
if (this._state == "resolved") {
continuation(this._resolvedValue);
}
return this;
};
PromiseWrapper.prototype.fail = function (continuation) {
this._fail.push(continuation);
if (this._state == "failed") {
continuation(this._rejectedError);
}
return this;
};
PromiseWrapper.prototype.always = function (continuation) {
this._always.push(continuation);
if (this._state == "resolved") {
continuation(this._resolvedValue);
}
if (this._state == "failed") {
continuation(this._rejectedError);
}
return this;
};
return PromiseWrapper;
}());
export { PromiseWrapper };
var PromiseFactory = /** @class */ /*@__PURE__*/ (function () {
function PromiseFactory() {
this._wrapper = null;
}
PromiseFactory.prototype.resolve = function (result) {
if (this._resolve) {
this._resolve(result);
}
};
PromiseFactory.prototype.reject = function (error) {
if (this._reject) {
this._reject(error);
}
};
PromiseFactory.prototype.promise = function () {
var _this = this;
this._promise = new Promise(function (resolve, reject) {
_this._resolve = resolve;
_this._reject = reject;
});
this._wrapper = new PromiseWrapper(this._promise);
return this._wrapper;
};
return PromiseFactory;
}());
export { PromiseFactory };