igniteui-react-core
Version:
Ignite UI React Core.
413 lines (412 loc) • 14.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.
*/
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
*/
export let SyncableObservableCollection$2 = /*@__PURE__*/ (() => {
class SyncableObservableCollection$2 extends Base {
get syncTarget() {
return this.a;
}
set syncTarget(a) {
let b = this.a;
this.a = a;
this.ah(b, this.a);
}
addOneWayTarget(a) {
this.r.add(a);
this.ao(a, true);
}
removeOneWayTarget(a) {
this.r.remove(a);
}
get compare() {
return this._compare;
}
set compare(a) {
this._compare = a;
}
get createTo() {
return this._createTo;
}
set createTo(a) {
this._createTo = a;
}
get createFrom() {
return this._createFrom;
}
set createFrom(a) {
this._createFrom = a;
}
get shouldDetachOnTargetChange() {
return this._shouldDetachOnTargetChange;
}
set shouldDetachOnTargetChange(a) {
this._shouldDetachOnTargetChange = a;
}
ah(a, b) {
if (a != null) {
a.removeListener(runOn(this, this.ar));
}
this.ao(this.a, false);
if (b != null) {
b.addListener(runOn(this, this.ar));
}
}
ao(a, b) {
if (a == null) {
return;
}
this.h = true;
let c = new List$1(this.$t1, 0);
let d = new HashSet$1(this.$t1, 0);
for (let 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 (let f = 0; f < a.all.count; f++) {
if (!this.l(d, a.all.item(f))) {
let 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;
}
l(a, b) {
if (this.compare == null) {
throw new InvalidOperationException(1, "SyncableObservableCollection has no Compare function provided.");
}
for (let c of fromEnum(a)) {
if (this.compare(c, b)) {
return true;
}
}
return false;
}
ap(a, b) {
let c = new List$1(Number_$type, 0);
let d = 0;
for (let 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 (let f = c.count - 1; f >= 0; f--) {
b.removeAt(f);
}
for (; d < a.count; d++) {
b.add(a._inner[d]);
}
}
aq(a, b) {
let c = new List$1(Number_$type, 0);
let d = 0;
for (let 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 (let f = c.count - 1; f >= 0; f--) {
b.removeAt(f);
}
for (; d < a.count; d++) {
b.add(this.createTo(a._inner[d]));
}
}
ar(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;
}
let c = this.a.all;
this.i = true;
this.an(this.$t1, this.$t2, b, this.all, c);
this.i = false;
}
ag(a) {
}
am(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) {
let 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 (let d = 0; d < this.r.count; d++) {
let e = this.r._inner[d].all;
this.g = true;
this.an(this.$t2, this.$t1, b, e, this.all);
this.g = false;
}
}
}
an($t, $f, a, b, c) {
switch (a.action) {
case 0:
if (a.newItems != null) {
for (let d = 0; d < a.newItems.count; d++) {
let 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 (let f = 0; f < a.oldItems.count; f++) {
b.removeAt(a.oldStartingIndex);
}
}
break;
case 2:
if (a.oldItems != null) {
for (let g = 0; g < a.oldItems.count; g++) {
b.removeAt(a.oldStartingIndex);
}
}
if (a.newItems != null) {
for (let h = 0; h < a.newItems.count; h++) {
let 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();
for (let j of fromEnum(c)) {
let 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));
}
break;
}
}
constructor($t1, $t2, a, ..._rest) {
super();
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));
let c = this._inner;
c.collectionChanged = delegateCombine(c.collectionChanged, runOn(this, this.y));
}
break;
case 1:
{
let c = _rest[0];
this._inner = c;
}
break;
}
}
ae(a) {
if (this._inner != null) {
let b = this._inner;
b.collectionChanged = delegateRemove(b.collectionChanged, runOn(this, this.y));
}
this._inner = a;
if (this._inner != null) {
let c = this._inner;
c.collectionChanged = delegateCombine(c.collectionChanged, runOn(this, this.y));
}
}
y(a, b) {
if (this.f != null) {
this.f();
}
for (let c of fromEnum(this.q)) {
c.onChanged(this);
}
}
add(a) {
this._inner.add(a);
return true;
}
add1(a, b) {
this._inner.insert(a, b);
}
clear() {
let a = new List$1(Delegate_$type, 0);
for (let b of fromEnum(this.p)) {
a.add(b);
}
for (let c of fromEnum(a)) {
c();
}
this._inner.clear();
}
get(a) {
return this._inner._inner[a];
}
indexOf(a) {
return this._inner.indexOf(a);
}
remove1(a) {
let b = this._inner.contains(a);
this._inner.remove(a);
return b;
}
contains(a) {
return this._inner.contains(a);
}
remove(a) {
let b = this._inner._inner[a];
this._inner.removeAt(a);
return b;
}
set(a, b) {
this._inner.item(a, b);
return b;
}
size() {
return this._inner.count;
}
addChangedListener(a) {
this.q.add(a);
}
removeChangedListener(a) {
this.q.remove(a);
}
addListener(a) {
let b = this._inner;
b.collectionChanged = delegateCombine(b.collectionChanged, a);
}
removeListener(a) {
let b = this._inner;
b.collectionChanged = delegateRemove(b.collectionChanged, a);
}
ab(a) {
this.p.add(a);
}
aj(a) {
this.p.remove(a);
}
get all() {
return this._inner;
}
}
SyncableObservableCollection$2.$t = /*@__PURE__*/ markType(SyncableObservableCollection$2, 'SyncableObservableCollection$2');
return SyncableObservableCollection$2;
})();
/**
* @hidden
*/
export let SyncableObservableCollection$1 = /*@__PURE__*/ (() => {
class SyncableObservableCollection$1 extends SyncableObservableCollection$2 {
constructor($t) {
super($t, $t, 0);
this.$t = null;
this.$t = $t;
this.$type = this.$type.specialize(this.$t);
this.compare = (a, b) => Base.equalsStatic(a, getBoxIfEnum(this.$t, b));
this.createFrom = (a) => a;
this.createTo = (a) => a;
}
}
SyncableObservableCollection$1.$t = /*@__PURE__*/ markType(SyncableObservableCollection$1, 'SyncableObservableCollection$1', /*@__PURE__*/ SyncableObservableCollection$2.$.specialize(0, 0));
return SyncableObservableCollection$1;
})();