igniteui-webcomponents-datasources
Version:
Reference custom data providers for the Ignite UI Web Components data source.
161 lines (160 loc) • 4.49 kB
JavaScript
import { __values } from "tslib";
import { fromEnum } from "igniteui-webcomponents-core";
export function toArray(en) {
return Array.from(fromEnum(en));
}
export function first(iter) {
var e_1, _a;
try {
for (var iter_1 = __values(iter), iter_1_1 = iter_1.next(); !iter_1_1.done; iter_1_1 = iter_1.next()) {
var v = iter_1_1.value;
return v;
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (iter_1_1 && !iter_1_1.done && (_a = iter_1.return))
_a.call(iter_1);
}
finally {
if (e_1)
throw e_1.error;
}
}
throw new Error("Iterable contained no elements, expected at least one");
}
var LinkedList = /** @class */ /*@__PURE__*/ (function () {
function LinkedList() {
}
Object.defineProperty(LinkedList.prototype, "first", {
get: function () {
return this._first;
},
enumerable: false,
configurable: true
});
Object.defineProperty(LinkedList.prototype, "last", {
get: function () {
return this._last;
},
enumerable: false,
configurable: true
});
LinkedList.prototype.addFirst = function (item) {
if (this._first == null) {
this._first = new LinkedListNode(item);
this._last = this._first;
}
else {
var oldFirst = this._first;
this._first = new LinkedListNode(item);
this._first.next = oldFirst;
oldFirst.prev = this._first;
}
};
LinkedList.prototype.addLast = function (item) {
if (this._last == null) {
this._first = new LinkedListNode(item);
this._last = this._first;
}
else {
var oldLast = this._last;
this._last = new LinkedListNode(item);
this._last.prev = oldLast;
oldLast.next = this._last;
}
};
LinkedList.prototype.removeFirst = function () {
this.remove(this.first);
};
LinkedList.prototype.clear = function () {
this._first = null;
this._last = null;
};
LinkedList.prototype.contains = function (value) {
var curr = this.first;
while (curr != null) {
if (curr.value === value) {
return true;
}
curr = curr.next;
}
return false;
};
LinkedList.prototype.removeValue = function (value) {
var curr = this.first;
while (curr != null) {
if (curr.value === value) {
this.remove(curr);
return;
}
curr = curr.next;
}
};
LinkedList.prototype.remove = function (node) {
if (this._first == node) {
this._first = node.next;
if (node.next != null) {
node.next.prev = null;
}
}
if (this._last == node) {
this._last = node.prev;
if (node.prev != null) {
node.prev.next = null;
}
}
if (node.prev != null) {
node.prev.next = node.next;
}
if (node.next != null) {
node.next.prev = node.prev;
}
node.next = null;
node.prev = null;
};
return LinkedList;
}());
export { LinkedList };
var LinkedListNode = /** @class */ /*@__PURE__*/ (function () {
function LinkedListNode(item) {
if (item !== undefined) {
this.value = item;
}
}
Object.defineProperty(LinkedListNode.prototype, "value", {
get: function () {
return this._value;
},
set: function (value) {
this._value = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(LinkedListNode.prototype, "prev", {
get: function () {
return this._prev;
},
set: function (value) {
this._prev = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(LinkedListNode.prototype, "next", {
get: function () {
return this._next;
},
set: function (value) {
this._next = value;
},
enumerable: false,
configurable: true
});
return LinkedListNode;
}());
export { LinkedListNode };