lik/dist/lik.objectmap.js
2017-06-17 14:44:55 +02:00

106 lines
4.9 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./lik.plugins");
/**
* allows keeping track of objects
*/
class Objectmap {
/**
* returns a new instance
*/
constructor() {
this.objectArray = [];
// nothing here
}
/**
* add object to Objectmap
*/
add(objectArg) {
this.objectArray.push(objectArg);
}
/**
* like .add but adds an whole array of objects
*/
addArray(objectArrayArg) {
for (let item of objectArrayArg) {
this.add(item);
}
}
/**
* check if object is in Objectmap
*/
checkForObject(objectArg) {
return this.objectArray.indexOf(objectArg) !== -1;
}
/**
* find object
*/
find(findFunction) {
let resultArray = this.objectArray.filter(findFunction);
if (resultArray.length > 0) {
return resultArray[0];
}
else {
return null;
}
}
/**
* finds a specific element and then removes it
*/
findOneAndRemove(findFunction) {
let foundElement = this.find(findFunction);
if (foundElement) {
this.remove(foundElement);
}
return foundElement;
}
/**
* run function for each item in Objectmap
*/
forEach(functionArg) {
return this.objectArray.forEach(functionArg);
}
/**
* gets an object in the Observablemap and removes it, so it can't be retrieved again
*/
getOneAndRemove() {
return this.objectArray.shift();
}
/**
* returns a cloned array of all the objects currently in the Objectmap
*/
getArray() {
return plugins.lodash.cloneDeep(this.objectArray);
}
/**
* check if Objectmap ist empty
*/
isEmpty() {
if (this.objectArray.length === 0) {
return true;
}
else {
return false;
}
}
/**
* remove object from Objectmap
*/
remove(objectArg) {
let replacementArray = [];
for (let item of this.objectArray) {
if (item !== objectArg) {
replacementArray.push(item);
}
}
this.objectArray = replacementArray;
}
/**
* wipe Objectmap
*/
wipe() {
this.objectArray = [];
}
}
exports.Objectmap = Objectmap;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6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