lik/dist/lik.objectmap.js

70 lines
3.2 KiB
JavaScript

"use strict";
/**
* 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 = [];
}
}
exports.Objectmap = Objectmap;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQVVBOztHQUVHO0FBQ0g7SUFHSTs7T0FFRztJQUNIO1FBTFEsZ0JBQVcsR0FBUSxFQUFFLENBQUE7SUFPN0IsQ0FBQztJQUVEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFNBQVk7UUFDWixJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUNwQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxRQUFRLENBQUMsY0FBbUI7UUFDeEIsR0FBRyxDQUFDLENBQUMsSUFBSSxJQUFJLElBQUksY0FBYyxDQUFDLENBQUMsQ0FBQ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