implement find functionality into Objectmap

This commit is contained in:
Philipp Kunz 2016-08-08 16:00:14 +02:00
parent 49f0d7018d
commit ac2267d910
5 changed files with 57 additions and 9 deletions

View File

@ -1,6 +1,9 @@
export interface IObjectmapForEach { export interface IObjectmapForEachFunction {
(itemArg: any): void; (itemArg: any): void;
} }
export interface IObjectmapFindFunction {
(itemArg: any): boolean;
}
/** /**
* allows keeping track of objects * allows keeping track of objects
*/ */
@ -22,10 +25,14 @@ export declare class Objectmap {
* check if object is in Objectmap * check if object is in Objectmap
*/ */
checkForObject(objectArg: any): number; checkForObject(objectArg: any): number;
/**
* find object
*/
find(findFunction: IObjectmapFindFunction): any;
/** /**
* run function for each item in Objectmap * run function for each item in Objectmap
*/ */
forEach(functionArg: IObjectmapForEach): void; forEach(functionArg: IObjectmapForEachFunction): void;
/** /**
* wipe Objectmap * wipe Objectmap
*/ */

14
dist/lik.objectmap.js vendored
View File

@ -1,4 +1,6 @@
"use strict"; "use strict";
;
;
/** /**
* allows keeping track of objects * allows keeping track of objects
*/ */
@ -38,6 +40,16 @@ class Objectmap {
return this.objectArray.indexOf(objectArg !== -1); return this.objectArray.indexOf(objectArg !== -1);
} }
; ;
/**
* find object
*/
find(findFunction) {
let resultArray = this.objectArray.filter(findFunction);
if (resultArray.length > 0) {
return resultArray[0];
}
;
}
/** /**
* run function for each item in Objectmap * run function for each item in Objectmap
*/ */
@ -52,4 +64,4 @@ class Objectmap {
} }
} }
exports.Objectmap = Objectmap; exports.Objectmap = Objectmap;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQU9BOztHQUVHO0FBQ0g7SUFHSTs7T0FFRztJQUNIO1FBTFEsZ0JBQVcsR0FBRyxFQUFFLENBQUM7SUFPekIsQ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QUFDLFdBQVcsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFDLENBQUEsQ0FBQztZQUN4QixNQUFNLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQzFCLENBQUM7UUFBQSxDQUFDO0lBQ04sQ0FBQztJQUdEOztPQUVHO0lBQ0gsT0FBTyxDQUFDLFdBQXFDO1FBQ3pDLE1BQU0sQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztJQUNqRCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJO1FBQ0EsSUFBSSxDQUFDLFdBQVcsR0FBRyxFQUFFLENBQUM7SUFDMUIsQ0FBQztBQUNMLENBQUM7QUEvRFksaUJBQVMsWUErRHJCLENBQUEifQ==

View File

@ -67,6 +67,12 @@ describe("lik", function () {
itemArg.should.have.ownProperty("propOne"); itemArg.should.have.ownProperty("propOne");
}); });
}); });
it("should correctly find an object", function () {
let myObject = { item1: "hello", item2: "hello2" };
testObjectmap.add(myObject);
let referenceObject = testObjectmap.find((itemArg) => { return (itemArg.item1 == "hello"); });
(myObject == referenceObject).should.be.true();
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxHQUFHLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDdEMsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixRQUFRLENBQUMsS0FBSyxFQUFDO0lBQ1gsUUFBUSxDQUFDLFdBQVcsRUFBQztRQUNqQixJQUFJLGFBQTJCLENBQUM7UUFDaEMsSUFBSSxXQUFXLEdBQUcsYUFBYSxDQUFDO1FBQ2hDLElBQUksV0F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xNQUFNLENBQUMsQ0FBQyxPQUFPLENBQUMsS0FBSyxJQUFJLE9BQU8sQ0FBQyxDQUFBLENBQUEsQ0FBQyxDQUFDLENBQUM7WUFDM0YsQ0FBQyxRQUFRLElBQUksZUFBZSxDQUFDLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxJQUFJLEVBQUUsQ0FBQztRQUNuRCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUMifQ==

View File

@ -73,6 +73,12 @@ describe("lik",function(){
testObjectmap.forEach(itemArg => { testObjectmap.forEach(itemArg => {
itemArg.should.have.ownProperty("propOne"); itemArg.should.have.ownProperty("propOne");
}) })
}) });
it("should correctly find an object",function(){
let myObject = {item1: "hello",item2: "hello2"};
testObjectmap.add(myObject);
let referenceObject = testObjectmap.find((itemArg) => {return (itemArg.item1 == "hello")});
(myObject == referenceObject).should.be.true();
});
}) })
}); });

View File

@ -1,9 +1,14 @@
import * as plugins from "./lik.plugins"; import * as plugins from "./lik.plugins";
export interface IObjectmapForEach { export interface IObjectmapForEachFunction {
(itemArg):void (itemArg:any):void
} };
export interface IObjectmapFindFunction {
(itemArg:any):boolean
};
/** /**
* allows keeping track of objects * allows keeping track of objects
@ -46,10 +51,22 @@ export class Objectmap {
return this.objectArray.indexOf(objectArg !== -1) return this.objectArray.indexOf(objectArg !== -1)
}; };
/**
* find object
*/
find(findFunction:IObjectmapFindFunction){
let resultArray = this.objectArray.filter(findFunction);
if (resultArray.length > 0){
return resultArray[0];
};
}
/** /**
* run function for each item in Objectmap * run function for each item in Objectmap
*/ */
forEach(functionArg:IObjectmapForEach){ forEach(functionArg:IObjectmapForEachFunction){
return this.objectArray.forEach(functionArg); return this.objectArray.forEach(functionArg);
} }