93 lines
4.4 KiB
JavaScript
93 lines
4.4 KiB
JavaScript
"use strict";
|
|
const plugins = require("./lik.plugins");
|
|
/**
|
|
* allows keeping track of objects
|
|
*/
|
|
class Objectmap {
|
|
/**
|
|
* returns a new instance
|
|
*/
|
|
constructor() {
|
|
this.objectArray = [];
|
|
}
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|
|
/**
|
|
* 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();
|
|
}
|
|
/**
|
|
* finds a specific element and then removes it
|
|
*/
|
|
findOneAndRemove(findFunction) {
|
|
let foundElement = this.find(findFunction);
|
|
if (foundElement) {
|
|
this.remove(foundElement);
|
|
}
|
|
return foundElement;
|
|
}
|
|
/**
|
|
* returns a cloned array of all the objects currently in the Objectmap
|
|
*/
|
|
getArray() {
|
|
return plugins.lodash.cloneDeep(this.objectArray);
|
|
}
|
|
/**
|
|
* remove object from Objectmap
|
|
*/
|
|
remove(objectArg) {
|
|
let replacementArray = [];
|
|
for (let item of this.objectArray) {
|
|
if (item !== objectArg) {
|
|
replacementArray.push(item);
|
|
}
|
|
}
|
|
this.objectArray = replacementArray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