lik/dist/lik.objectmap.js

105 lines
4.9 KiB
JavaScript
Raw Normal View History

2016-07-30 22:54:46 +00:00
"use strict";
2017-04-09 14:29:14 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2016-09-29 20:05:20 +00:00
const plugins = require("./lik.plugins");
2016-07-30 22:54:46 +00:00
/**
* allows keeping track of objects
*/
class Objectmap {
2016-08-07 16:08:52 +00:00
/**
* returns a new instance
*/
2016-07-30 22:54:46 +00:00
constructor() {
this.objectArray = [];
}
2016-07-31 12:36:28 +00:00
/**
* add object to Objectmap
*/
2016-07-30 22:54:46 +00:00
add(objectArg) {
this.objectArray.push(objectArg);
}
2016-09-22 10:00:33 +00:00
/**
* like .add but adds an whole array of objects
*/
addArray(objectArrayArg) {
for (let item of objectArrayArg) {
this.add(item);
}
}
2016-07-31 12:36:28 +00:00
/**
* check if object is in Objectmap
*/
2016-07-30 22:54:46 +00:00
checkForObject(objectArg) {
return this.objectArray.indexOf(objectArg) !== -1;
2016-07-30 22:54:46 +00:00
}
/**
* find object
*/
find(findFunction) {
let resultArray = this.objectArray.filter(findFunction);
if (resultArray.length > 0) {
return resultArray[0];
}
else {
2016-09-22 10:00:33 +00:00
return null;
}
}
2016-11-19 22:54:52 +00:00
/**
* finds a specific element and then removes it
*/
findOneAndRemove(findFunction) {
let foundElement = this.find(findFunction);
if (foundElement) {
this.remove(foundElement);
}
return foundElement;
}
2016-07-31 12:36:28 +00:00
/**
* run function for each item in Objectmap
*/
forEach(functionArg) {
2016-07-31 13:01:24 +00:00
return this.objectArray.forEach(functionArg);
2016-07-31 12:36:28 +00:00
}
/**
* gets an object in the Observablemap and removes it, so it can't be retrieved again
2016-07-31 12:36:28 +00:00
*/
getOneAndRemove() {
return this.objectArray.shift();
}
2016-09-29 20:05:20 +00:00
/**
* returns a cloned array of all the objects currently in the Objectmap
*/
getArray() {
return plugins.lodash.cloneDeep(this.objectArray);
}
2016-11-19 22:54:52 +00:00
/**
* 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 = [];
}
2016-07-30 22:54:46 +00:00
}
exports.Objectmap = Objectmap;
2017-04-09 14:29:14 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx5Q0FBd0M7QUFVeEM7O0dBRUc7QUFDSDtJQUdJOztPQUVHO0lBQ0g7UUFMUSxnQkFBVyxHQUFRLEVBQUUsQ0FBQTtJQU83QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxHQUFHLENBQUMsU0FBWTtRQUNaLElBQUksQ0FBQyxXQUFXLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFBO0lBQ3BDLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxjQUFtQjtRQUN4QixHQUFHLENBQUMsQ0FBQyxJQUFJLElBQUksSUFBSSxjQUFjLENBQUMsQ0FBQyxDQUFDO1lBQzlCLElBQUksQ0FBQyxHQUFHLENBQUMsSUFBSSxDQUFDLENBQUE7UUFDbEIsQ0FBQztJQUNMLENBQUM7SUFFRDs7T0FFRztJQUNILGNBQWMsQ0FBQyxTQUFZO1FBQ3ZCLE1BQU0sQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQTtJQUNyRCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJLENBQUMsWUFBdUM7UUFDeEMsSUFBSSxXQU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