@zohodesk/utils
Version:
DOT Utils Collection
63 lines (53 loc) • 1.31 kB
JavaScript
import { appendToArray, deleteFromArrayOfObjectById, deleteFromArrayByItem, updateArrayOfObjectItemById, updateArrayItemByItem, emptyArray } from "./arrayCRUD";
import { DUMMY_ARRAY } from "../constantProps/constant";
class ArrayManager {
constructor() {
let initialArray = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DUMMY_ARRAY;
this.array = initialArray;
}
addValue(item) {
this.array = appendToArray({
array: this.array,
item
});
return this.array;
}
removeValueById(id) {
this.array = deleteFromArrayOfObjectById({
arrayOfObject: this.array,
id
});
return this.array;
}
removeValueByItem(item) {
this.array = deleteFromArrayByItem({
array: this.array,
item
});
return this.array;
}
clearValue() {
this.array = emptyArray();
return this.array;
}
updateValueById(id, newItem) {
this.array = updateArrayOfObjectItemById({
arrayOfObject: this.array,
id,
newItem
});
return this.array;
}
updateValueByItem(currentItem, newItem) {
this.array = updateArrayItemByItem({
array: this.array,
currentItem,
newItem
});
return this.array;
}
getValue() {
return this.array;
}
}
export default ArrayManager;