lik/dist/lik.objectmap.js

77 lines
3.5 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);
}
}
/**
* remove object from Objectmap
*/
remove(objectArg) {
let replacmentArray = [];
for (let item of this.objectArray) {
if (item !== objectArg) {
replacmentArray.push(item);
}
}
this.objectArray = replacmentArray;
}
/**
* 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);
}
/**
* wipe Objectmap
*/
wipe() {
this.objectArray = [];
}
/**
* returns a cloned array of all the objects currently in the Objectmap
*/
getArray() {
return plugins.lodash.cloneDeep(this.objectArray);
}
}
exports.Objectmap = Objectmap;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHlDQUF3QztBQVV4Qzs7R0FFRztBQUNIO0lBR0k7O09BRUc7SUFDSDtRQUxRLGdCQUFXLEdBQVEsRUFBRSxDQUFBO0lBTzdCLENBQUM7SUFFRDs7T0FFRztJQUNILEdBQUcsQ0FBQyxTQUFZO1FBQ1osSUFBSSxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDcEMsQ0FBQztJQUVEOztPQUVHO0lBQ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