add forEach to Objectmap

This commit is contained in:
Philipp Kunz 2016-07-31 14:36:28 +02:00
parent 24b260c3da
commit 9d856ad813
5 changed files with 76 additions and 2 deletions

View File

@ -1,10 +1,29 @@
export interface IObjectmapForEach {
(itemArg: any): void;
}
/** /**
* allows keeping track of objects * allows keeping track of objects
*/ */
export declare class Objectmap { export declare class Objectmap {
private objectArray; private objectArray;
/**
* add object to Objectmap
*/
add(objectArg: any): void; add(objectArg: any): void;
/**
* remove object from Objectmap
*/
remove(objectArg: any): void; remove(objectArg: any): void;
/**
* check if object is in Objectmap
*/
checkForObject(objectArg: any): number; checkForObject(objectArg: any): number;
/**
* run function for each item in Objectmap
*/
forEach(functionArg: IObjectmapForEach): void;
/**
* wipe Objectmap
*/
wipe(): void; wipe(): void;
} }

20
dist/lik.objectmap.js vendored
View File

@ -6,10 +6,16 @@ class Objectmap {
constructor() { constructor() {
this.objectArray = []; this.objectArray = [];
} }
/**
* add object to Objectmap
*/
add(objectArg) { add(objectArg) {
this.objectArray.push(objectArg); this.objectArray.push(objectArg);
} }
; ;
/**
* remove object from Objectmap
*/
remove(objectArg) { remove(objectArg) {
let replacmentArray = []; let replacmentArray = [];
for (let item of this.objectArray) { for (let item of this.objectArray) {
@ -21,13 +27,25 @@ class Objectmap {
this.objectArray = replacmentArray; this.objectArray = replacmentArray;
} }
; ;
/**
* check if object is in Objectmap
*/
checkForObject(objectArg) { checkForObject(objectArg) {
return this.objectArray.indexOf(objectArg !== -1); return this.objectArray.indexOf(objectArg !== -1);
} }
; ;
/**
* run function for each item in Objectmap
*/
forEach(functionArg) {
this.objectArray.forEach(functionArg);
}
/**
* wipe Objectmap
*/
wipe() { wipe() {
this.objectArray = []; this.objectArray = [];
} }
} }
exports.Objectmap = Objectmap; exports.Objectmap = Objectmap;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbI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SJ9

View File

@ -62,6 +62,11 @@ describe("lik", function () {
testObjectmap.checkForObject(testObject1).should.be.false; testObjectmap.checkForObject(testObject1).should.be.false;
testObjectmap.checkForObject(testObject2).should.be.true; testObjectmap.checkForObject(testObject2).should.be.true;
}); });
it("should correctly run a function forEach map object", function () {
testObjectmap.forEach(itemArg => {
itemArg.should.have.ownProperty("propOne");
});
});
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxHQUFHLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDdEMsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixRQUFRLENBQUMsS0FBSyxFQUFDO0lBQ1gsUUFBUSxDQUFDLFdBQVcsRUFBQztRQUNqQixJQUFJLGFBQTJCLENBQUM7UUFDaEMsSUFBSSxXQUFXLEdBQUcsYUFBYSxDQUFDO1FBQ2hDLElBQUksV0FBVyxHQUFHLGFBQWEsQ0FBQztRQUNoQyxJQUFJLFdBQVcsR0FBRyxhQUFhLENBQUM7UUFDaEMsRUFBRSxDQUFDLHdDQUF3QyxFQUFDO1lBQ3hDLGFBQWEsR0FBRyxJQUFJLEdBQUcsQ0FBQyxTQUFTLEVBQUUsQ0FBQztZQUNwQyxhQUFhLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsR0FBRyxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQ3RELENBQUMsQ0FBQyxDQUFDO1FBQ0gsRUFBRSxDQUFDLG9EQUFvRCxFQUFDO1lBQ3BELGFBQWEsQ0FBQyxXQUFXLENBQUMsV0FBVyxDQUFDLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxLQUFLLEVBQU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QyxPQUFPO2dCQUN6QixPQUFPLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsU0FBUyxDQUFDLENBQUM7WUFDL0MsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUMifQ==

View File

@ -69,5 +69,10 @@ describe("lik",function(){
testObjectmap.checkForObject(testObject1).should.be.false; testObjectmap.checkForObject(testObject1).should.be.false;
testObjectmap.checkForObject(testObject2).should.be.true; testObjectmap.checkForObject(testObject2).should.be.true;
}); });
it("should correctly run a function forEach map object",function(){
testObjectmap.forEach(itemArg => {
itemArg.should.have.ownProperty("propOne");
})
})
}) })
}); });

View File

@ -1,13 +1,25 @@
import * as plugins from "./lik.plugins"; import * as plugins from "./lik.plugins";
export interface IObjectmapForEach {
(itemArg):void
}
/** /**
* allows keeping track of objects * allows keeping track of objects
*/ */
export class Objectmap { export class Objectmap {
private objectArray = []; private objectArray = [];
/**
* add object to Objectmap
*/
add(objectArg){ add(objectArg){
this.objectArray.push(objectArg); this.objectArray.push(objectArg);
}; };
/**
* remove object from Objectmap
*/
remove(objectArg){ remove(objectArg){
let replacmentArray = []; let replacmentArray = [];
for(let item of this.objectArray){ for(let item of this.objectArray){
@ -17,9 +29,24 @@ export class Objectmap {
}; };
this.objectArray = replacmentArray; this.objectArray = replacmentArray;
}; };
/**
* check if object is in Objectmap
*/
checkForObject(objectArg){ checkForObject(objectArg){
return this.objectArray.indexOf(objectArg !== -1) return this.objectArray.indexOf(objectArg !== -1)
}; };
/**
* run function for each item in Objectmap
*/
forEach(functionArg:IObjectmapForEach){
this.objectArray.forEach(functionArg);
}
/**
* wipe Objectmap
*/
wipe(){ wipe(){
this.objectArray = []; this.objectArray = [];
} }