@formily/reactive
Version:
> Web Reactive Library Like Mobx
63 lines • 1.95 kB
JavaScript
export var toArray = function (value) {
return Array.isArray(value)
? value
: value !== undefined && value !== null
? [value]
: [];
};
var ArraySet = /** @class */ (function () {
function ArraySet(value) {
if (value === void 0) { value = []; }
this.forEachIndex = 0;
this.value = value;
}
ArraySet.prototype.add = function (item) {
if (!this.has(item)) {
this.value.push(item);
}
};
ArraySet.prototype.has = function (item) {
return this.value.indexOf(item) > -1;
};
ArraySet.prototype.delete = function (item) {
var len = this.value.length;
if (len === 0)
return;
if (len === 1 && this.value[0] === item) {
this.value = [];
return;
}
var findIndex = this.value.indexOf(item);
if (findIndex > -1) {
this.value.splice(findIndex, 1);
if (findIndex <= this.forEachIndex) {
this.forEachIndex -= 1;
}
}
};
ArraySet.prototype.forEach = function (callback) {
if (this.value.length === 0)
return;
this.forEachIndex = 0;
for (; this.forEachIndex < this.value.length; this.forEachIndex++) {
callback(this.value[this.forEachIndex]);
}
};
ArraySet.prototype.batchDelete = function (callback) {
if (this.value.length === 0)
return;
this.forEachIndex = 0;
for (; this.forEachIndex < this.value.length; this.forEachIndex++) {
var value = this.value[this.forEachIndex];
this.value.splice(this.forEachIndex, 1);
this.forEachIndex--;
callback(value);
}
};
ArraySet.prototype.clear = function () {
this.value.length = 0;
};
return ArraySet;
}());
export { ArraySet };
//# sourceMappingURL=array.js.map