igniteui-react-core
Version:
Ignite UI React Core.
531 lines (530 loc) • 18.5 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.
*/
import { __extends, __values } from "tslib";
import { Base, runOn, fromEnum, Number_$type, getBoxIfEnum, typeCastObjTo$t, delegateCombine, delegateRemove, Delegate_$type, markType } from "./type";
import { ObservableCollection$1 } from "./ObservableCollection$1";
import { List$1 } from "./List$1";
import { HashSet$1 } from "./HashSet$1";
import { InvalidOperationException } from "./InvalidOperationException";
import { SyncableObservableCollectionChangedListener_$type } from "./SyncableObservableCollectionChangedListener";
/**
* @hidden
*/
var SyncableObservableCollection$2 = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(SyncableObservableCollection$2, _super);
function SyncableObservableCollection$2($t1, $t2, a) {
var _rest = [];
for (var _i = 3; _i < arguments.length; _i++) {
_rest[_i - 3] = arguments[_i];
}
var _this = _super.call(this) || this;
_this.$t1 = null;
_this.$t2 = null;
_this.a = null;
_this.r = new List$1(SyncableObservableCollection$1.$.specialize(_this.$t2), 0);
_this._compare = null;
_this._createTo = null;
_this._createFrom = null;
_this._shouldDetachOnTargetChange = false;
_this.h = false;
_this.i = false;
_this.g = false;
_this._inner = null;
_this.q = new List$1(SyncableObservableCollectionChangedListener_$type, 0);
_this.p = new List$1(Delegate_$type, 0);
_this.f = null;
_this.$t1 = $t1;
_this.$t2 = $t2;
_this.$type = _this.$type.specialize(_this.$t1, _this.$t2);
a = (a == void 0) ? 0 : a;
switch (a) {
case 0:
{
_this._inner = new ObservableCollection$1(_this.$t1, 0);
_this.addListener(runOn(_this, _this.am));
var c = _this._inner;
c.collectionChanged = delegateCombine(c.collectionChanged, runOn(_this, _this.y));
}
break;
case 1:
{
var c = _rest[0];
_this._inner = c;
}
break;
}
return _this;
}
Object.defineProperty(SyncableObservableCollection$2.prototype, "syncTarget", {
get: function () {
return this.a;
},
set: function (a) {
var b = this.a;
this.a = a;
this.ah(b, this.a);
},
enumerable: false,
configurable: true
});
SyncableObservableCollection$2.prototype.addOneWayTarget = function (a) {
this.r.add(a);
this.ao(a, true);
};
SyncableObservableCollection$2.prototype.removeOneWayTarget = function (a) {
this.r.remove(a);
};
Object.defineProperty(SyncableObservableCollection$2.prototype, "compare", {
get: function () {
return this._compare;
},
set: function (a) {
this._compare = a;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SyncableObservableCollection$2.prototype, "createTo", {
get: function () {
return this._createTo;
},
set: function (a) {
this._createTo = a;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SyncableObservableCollection$2.prototype, "createFrom", {
get: function () {
return this._createFrom;
},
set: function (a) {
this._createFrom = a;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SyncableObservableCollection$2.prototype, "shouldDetachOnTargetChange", {
get: function () {
return this._shouldDetachOnTargetChange;
},
set: function (a) {
this._shouldDetachOnTargetChange = a;
},
enumerable: false,
configurable: true
});
SyncableObservableCollection$2.prototype.ah = function (a, b) {
if (a == b) {
return;
}
if (a != null) {
a.removeListener(runOn(this, this.ar));
}
this.ao(this.a, false);
if (b != null) {
b.addListener(runOn(this, this.ar));
}
};
SyncableObservableCollection$2.prototype.ao = function (a, b) {
if (a == null) {
return;
}
this.h = true;
var c = new List$1(this.$t1, 0);
var d = new HashSet$1(this.$t1, 0);
for (var e = 0; e < this.all.count; e++) {
if (!d.contains(this.all.item(e))) {
c.add(this.all.item(e));
d.add_1(this.all.item(e));
}
}
if (!b) {
for (var f = 0; f < a.all.count; f++) {
if (!this.l(d, a.all.item(f))) {
var g = this.createFrom(a.all.item(f));
c.add(g);
d.add_1(g);
}
}
}
if (!b) {
this.ap(c, this.all);
}
this.aq(c, a.all);
this.h = false;
};
SyncableObservableCollection$2.prototype.l = function (a, b) {
var e_1, _a;
if (this.compare == null) {
throw new InvalidOperationException(1, "SyncableObservableCollection has no Compare function provided.");
}
try {
for (var _b = __values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
var c = _c.value;
if (this.compare(c, b)) {
return true;
}
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_1)
throw e_1.error;
}
}
return false;
};
SyncableObservableCollection$2.prototype.ap = function (a, b) {
var c = new List$1(Number_$type, 0);
var d = 0;
for (var e = 0; e < b.count; e++) {
if (getBoxIfEnum(this.$t1, b.item(e)) == null) {
c.add(e);
continue;
}
if (d > a.count - 1) {
c.add(e);
continue;
}
if (Base.equalsStatic(b.item(e), getBoxIfEnum(this.$t1, a._inner[d]))) {
d++;
continue;
}
b.insert(e, a._inner[d]);
d++;
}
for (var f = c.count - 1; f >= 0; f--) {
b.removeAt(f);
}
for (; d < a.count; d++) {
b.add(a._inner[d]);
}
};
SyncableObservableCollection$2.prototype.aq = function (a, b) {
var c = new List$1(Number_$type, 0);
var d = 0;
for (var e = 0; e < b.count; e++) {
if (getBoxIfEnum(this.$t2, b.item(e)) == null) {
c.add(e);
continue;
}
if (d > a.count - 1) {
c.add(e);
continue;
}
if (Base.equalsStatic(b.item(e), getBoxIfEnum(this.$t1, a._inner[d]))) {
d++;
continue;
}
b.insert(e, this.createTo(a._inner[d]));
d++;
}
for (var f = c.count - 1; f >= 0; f--) {
b.removeAt(f);
}
for (; d < a.count; d++) {
b.add(this.createTo(a._inner[d]));
}
};
SyncableObservableCollection$2.prototype.ar = function (a, b) {
if (this.a == null) {
return;
}
if (this.h) {
return;
}
if (this.g) {
return;
}
if (this.shouldDetachOnTargetChange) {
this.syncTarget = null;
this.r.clear();
return;
}
var c = this.a.all;
this.i = true;
this.an(this.$t1, this.$t2, b, this.all, c);
this.i = false;
};
SyncableObservableCollection$2.prototype.ag = function (a) {
};
SyncableObservableCollection$2.prototype.am = function (a, b) {
this.ag(b);
if (this.a == null && this.r.count == 0) {
return;
}
if (this.h) {
return;
}
if (this.i) {
return;
}
if (this.a != null) {
var c = this.a.all;
this.g = true;
this.an(this.$t2, this.$t1, b, c, this.all);
this.g = false;
}
if (this.r.count > 0) {
for (var d = 0; d < this.r.count; d++) {
var e = this.r._inner[d].all;
this.g = true;
this.an(this.$t2, this.$t1, b, e, this.all);
this.g = false;
}
}
};
SyncableObservableCollection$2.prototype.an = function ($t, $f, a, b, c) {
var e_2, _a;
switch (a.action) {
case 0:
if (a.newItems != null) {
for (var d = 0; d < a.newItems.count; d++) {
var e = a.newItems.item(d);
if ($f != $t) {
if ($f == this.$t1) {
e = getBoxIfEnum(this.$t2, this.createTo(typeCastObjTo$t(this.$t1, a.newItems.item(d))));
}
if ($f == this.$t2) {
e = getBoxIfEnum(this.$t1, this.createFrom(typeCastObjTo$t(this.$t2, a.newItems.item(d))));
}
}
b.insert(d + a.newStartingIndex, typeCastObjTo$t($t, e));
}
}
break;
case 1:
if (a.oldItems != null) {
for (var f = 0; f < a.oldItems.count; f++) {
b.removeAt(a.oldStartingIndex);
}
}
break;
case 2:
if (a.oldItems != null) {
for (var g = 0; g < a.oldItems.count; g++) {
b.removeAt(a.oldStartingIndex);
}
}
if (a.newItems != null) {
for (var h = 0; h < a.newItems.count; h++) {
var i = a.newItems.item(h);
if ($f != $t) {
if ($f == this.$t1) {
i = getBoxIfEnum(this.$t2, this.createTo(typeCastObjTo$t(this.$t1, a.newItems.item(h))));
}
if ($f == this.$t2) {
i = getBoxIfEnum(this.$t1, this.createFrom(typeCastObjTo$t(this.$t2, a.newItems.item(h))));
}
}
b.insert(h + a.newStartingIndex, typeCastObjTo$t($t, a.newItems.item(h)));
}
}
break;
case 4:
b.clear();
try {
for (var _b = __values(fromEnum(c)), _c = _b.next(); !_c.done; _c = _b.next()) {
var j = _c.value;
var k = getBoxIfEnum($f, j);
if ($f != $t) {
if ($f == this.$t1) {
k = getBoxIfEnum(this.$t2, this.createTo(typeCastObjTo$t(this.$t1, k)));
}
if ($f == this.$t2) {
k = getBoxIfEnum(this.$t1, this.createFrom(typeCastObjTo$t(this.$t2, k)));
}
}
b.add(typeCastObjTo$t($t, k));
}
}
catch (e_2_1) {
e_2 = { error: e_2_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_2)
throw e_2.error;
}
}
break;
}
};
SyncableObservableCollection$2.prototype.ae = function (a) {
if (this._inner != null) {
var b = this._inner;
b.collectionChanged = delegateRemove(b.collectionChanged, runOn(this, this.y));
}
this._inner = a;
if (this._inner != null) {
var c = this._inner;
c.collectionChanged = delegateCombine(c.collectionChanged, runOn(this, this.y));
}
};
SyncableObservableCollection$2.prototype.y = function (a, b) {
var e_3, _a;
if (this.f != null) {
this.f();
}
try {
for (var _b = __values(fromEnum(this.q)), _c = _b.next(); !_c.done; _c = _b.next()) {
var c = _c.value;
c.onChanged(this);
}
}
catch (e_3_1) {
e_3 = { error: e_3_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_3)
throw e_3.error;
}
}
};
SyncableObservableCollection$2.prototype.add = function (a) {
this._inner.add(a);
return true;
};
SyncableObservableCollection$2.prototype.add1 = function (a, b) {
this._inner.insert(a, b);
};
SyncableObservableCollection$2.prototype.clear = function () {
var e_4, _a, e_5, _b;
var a = new List$1(Delegate_$type, 0);
try {
for (var _c = __values(fromEnum(this.p)), _d = _c.next(); !_d.done; _d = _c.next()) {
var b = _d.value;
a.add(b);
}
}
catch (e_4_1) {
e_4 = { error: e_4_1 };
}
finally {
try {
if (_d && !_d.done && (_a = _c.return))
_a.call(_c);
}
finally {
if (e_4)
throw e_4.error;
}
}
try {
for (var _e = __values(fromEnum(a)), _f = _e.next(); !_f.done; _f = _e.next()) {
var c = _f.value;
c();
}
}
catch (e_5_1) {
e_5 = { error: e_5_1 };
}
finally {
try {
if (_f && !_f.done && (_b = _e.return))
_b.call(_e);
}
finally {
if (e_5)
throw e_5.error;
}
}
this._inner.clear();
};
SyncableObservableCollection$2.prototype.get = function (a) {
return this._inner._inner[a];
};
SyncableObservableCollection$2.prototype.indexOf = function (a) {
return this._inner.indexOf(a);
};
SyncableObservableCollection$2.prototype.remove1 = function (a) {
var b = this._inner.contains(a);
this._inner.remove(a);
return b;
};
SyncableObservableCollection$2.prototype.contains = function (a) {
return this._inner.contains(a);
};
SyncableObservableCollection$2.prototype.remove = function (a) {
var b = this._inner._inner[a];
this._inner.removeAt(a);
return b;
};
SyncableObservableCollection$2.prototype.set = function (a, b) {
this._inner.item(a, b);
return b;
};
SyncableObservableCollection$2.prototype.size = function () {
return this._inner.count;
};
SyncableObservableCollection$2.prototype.addChangedListener = function (a) {
this.q.add(a);
};
SyncableObservableCollection$2.prototype.removeChangedListener = function (a) {
this.q.remove(a);
};
SyncableObservableCollection$2.prototype.addListener = function (a) {
var b = this._inner;
b.collectionChanged = delegateCombine(b.collectionChanged, a);
};
SyncableObservableCollection$2.prototype.removeListener = function (a) {
var b = this._inner;
b.collectionChanged = delegateRemove(b.collectionChanged, a);
};
SyncableObservableCollection$2.prototype.ab = function (a) {
this.p.add(a);
};
SyncableObservableCollection$2.prototype.aj = function (a) {
this.p.remove(a);
};
Object.defineProperty(SyncableObservableCollection$2.prototype, "all", {
get: function () {
return this._inner;
},
enumerable: false,
configurable: true
});
SyncableObservableCollection$2.$t = markType(SyncableObservableCollection$2, 'SyncableObservableCollection$2');
return SyncableObservableCollection$2;
}(Base));
export { SyncableObservableCollection$2 };
/**
* @hidden
*/
var SyncableObservableCollection$1 = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(SyncableObservableCollection$1, _super);
function SyncableObservableCollection$1($t) {
var _this = _super.call(this, $t, $t, 0) || this;
_this.$t = null;
_this.$t = $t;
_this.$type = _this.$type.specialize(_this.$t);
_this.compare = function (a, b) { return Base.equalsStatic(a, getBoxIfEnum(_this.$t, b)); };
_this.createFrom = function (a) { return a; };
_this.createTo = function (a) { return a; };
return _this;
}
SyncableObservableCollection$1.$t = markType(SyncableObservableCollection$1, 'SyncableObservableCollection$1', SyncableObservableCollection$2.$.specialize(0, 0));
return SyncableObservableCollection$1;
}(SyncableObservableCollection$2));
export { SyncableObservableCollection$1 };