now works with TypeScript Generic Types to track type usage of Objectmap
This commit is contained in:
parent
ba714fe637
commit
b85e79b07d
20
dist/lik.objectmap.d.ts
vendored
20
dist/lik.objectmap.d.ts
vendored
@ -1,13 +1,13 @@
|
||||
export interface IObjectmapForEachFunction {
|
||||
(itemArg: any): void;
|
||||
export interface IObjectmapForEachFunction<T> {
|
||||
(itemArg: T): void;
|
||||
}
|
||||
export interface IObjectmapFindFunction {
|
||||
(itemArg: any): boolean;
|
||||
export interface IObjectmapFindFunction<T> {
|
||||
(itemArg: T): boolean;
|
||||
}
|
||||
/**
|
||||
* allows keeping track of objects
|
||||
*/
|
||||
export declare class Objectmap {
|
||||
export declare class Objectmap<T> {
|
||||
private objectArray;
|
||||
/**
|
||||
* returns a new instance
|
||||
@ -16,23 +16,23 @@ export declare class Objectmap {
|
||||
/**
|
||||
* add object to Objectmap
|
||||
*/
|
||||
add(objectArg: any): void;
|
||||
add(objectArg: T): void;
|
||||
/**
|
||||
* remove object from Objectmap
|
||||
*/
|
||||
remove(objectArg: any): void;
|
||||
remove(objectArg: T): void;
|
||||
/**
|
||||
* check if object is in Objectmap
|
||||
*/
|
||||
checkForObject(objectArg: any): number;
|
||||
checkForObject(objectArg: T): boolean;
|
||||
/**
|
||||
* find object
|
||||
*/
|
||||
find(findFunction: IObjectmapFindFunction): any;
|
||||
find(findFunction: IObjectmapFindFunction<T>): T;
|
||||
/**
|
||||
* run function for each item in Objectmap
|
||||
*/
|
||||
forEach(functionArg: IObjectmapForEachFunction): void;
|
||||
forEach(functionArg: IObjectmapForEachFunction<T>): void;
|
||||
/**
|
||||
* wipe Objectmap
|
||||
*/
|
||||
|
5
dist/lik.objectmap.js
vendored
5
dist/lik.objectmap.js
vendored
@ -37,7 +37,7 @@ class Objectmap {
|
||||
* check if object is in Objectmap
|
||||
*/
|
||||
checkForObject(objectArg) {
|
||||
return this.objectArray.indexOf(objectArg !== -1);
|
||||
return this.objectArray.indexOf(objectArg) !== -1;
|
||||
}
|
||||
;
|
||||
/**
|
||||
@ -59,6 +59,7 @@ class Objectmap {
|
||||
forEach(functionArg) {
|
||||
return this.objectArray.forEach(functionArg);
|
||||
}
|
||||
;
|
||||
/**
|
||||
* wipe Objectmap
|
||||
*/
|
||||
@ -67,4 +68,4 @@ class Objectmap {
|
||||
}
|
||||
}
|
||||
exports.Objectmap = Objectmap;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9iamVjdG1hcC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2xpay5vYmplY3RtYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUtDLENBQUM7QUFJRCxDQUFDO0FBR0Y7O0dBRUc7QUFDSDtJQUdJOztPQUVHO0lBQ0g7UUFMUSxnQkFBVyxHQUFHLEVBQUUsQ0FBQztJQU96QixDQUFDOztJQUdEOztPQUVHO0lBQ0gsR0FBRyxDQUFDLFNBQVM7UUFDVCxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQztJQUNyQyxDQUFDOztJQUVEOztPQUVHO0lBQ0gsTUFBTSxDQUFDLFNBQVM7UUFDWixJQUFJLGVBQWUsR0FBRyxFQUFFLENBQUM7UUFDekIsR0FBRyxDQUFBLENBQUMsSUFBSSxJQUFJLElBQUksSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFBLENBQUM7WUFDOUIsRUFBRSxDQUFBLENBQUMsSUFBSSxLQUFLLFNBQVMsQ0FBQyxDQUFBLENBQUM7Z0JBQ25CLGVBQWUsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDL0IsQ0FBQztRQUNMLENBQUM7UUFBQSxDQUFDO1FBQ0YsSUFBSSxDQUFDLFdBQVcsR0FBRyxlQUFlLENBQUM7SUFDdkMsQ0FBQzs7SUFFRDs7T0FFRztJQUNILGNBQWMsQ0FBQyxTQUFTO1FBQ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ENBQUM7UUFDckIsQ0FBQztRQUFBLENBQUM7SUFDTixDQUFDO0lBR0Q7O09BRUc7SUFDSCxPQUFPLENBQUMsV0FBeUM7UUFDN0MsTUFBTSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0lBQ2pELENBQUM7O0lBRUQ7O09BRUc7SUFDSCxJQUFJO1FBQ0EsSUFBSSxDQUFDLFdBQVcsR0FBRyxFQUFFLENBQUM7SUFDMUIsQ0FBQztBQUNMLENBQUM7QUFqRVksaUJBQVMsWUFpRXJCLENBQUEifQ==
|
@ -1,25 +1,25 @@
|
||||
import * as plugins from "./lik.plugins";
|
||||
|
||||
|
||||
export interface IObjectmapForEachFunction {
|
||||
(itemArg:any):void
|
||||
export interface IObjectmapForEachFunction<T> {
|
||||
(itemArg: T): void
|
||||
};
|
||||
|
||||
export interface IObjectmapFindFunction {
|
||||
(itemArg:any):boolean
|
||||
export interface IObjectmapFindFunction<T> {
|
||||
(itemArg: T): boolean
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* allows keeping track of objects
|
||||
*/
|
||||
export class Objectmap {
|
||||
private objectArray = [];
|
||||
export class Objectmap<T> {
|
||||
private objectArray:T[] = [];
|
||||
|
||||
/**
|
||||
* returns a new instance
|
||||
*/
|
||||
constructor(){
|
||||
constructor() {
|
||||
|
||||
};
|
||||
|
||||
@ -27,17 +27,17 @@ export class Objectmap {
|
||||
/**
|
||||
* add object to Objectmap
|
||||
*/
|
||||
add(objectArg){
|
||||
add(objectArg:T) {
|
||||
this.objectArray.push(objectArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* remove object from Objectmap
|
||||
*/
|
||||
remove(objectArg){
|
||||
remove(objectArg:T) {
|
||||
let replacmentArray = [];
|
||||
for(let item of this.objectArray){
|
||||
if(item !== objectArg){
|
||||
for (let item of this.objectArray) {
|
||||
if (item !== objectArg) {
|
||||
replacmentArray.push(item);
|
||||
}
|
||||
};
|
||||
@ -47,17 +47,17 @@ export class Objectmap {
|
||||
/**
|
||||
* check if object is in Objectmap
|
||||
*/
|
||||
checkForObject(objectArg){
|
||||
return this.objectArray.indexOf(objectArg !== -1)
|
||||
checkForObject(objectArg:T) {
|
||||
return this.objectArray.indexOf(objectArg) !== -1
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* find object
|
||||
*/
|
||||
find(findFunction:IObjectmapFindFunction){
|
||||
find(findFunction: IObjectmapFindFunction<T>) {
|
||||
let resultArray = this.objectArray.filter(findFunction);
|
||||
if (resultArray.length > 0){
|
||||
if (resultArray.length > 0) {
|
||||
return resultArray[0];
|
||||
} else {
|
||||
return undefined;
|
||||
@ -68,14 +68,14 @@ export class Objectmap {
|
||||
/**
|
||||
* run function for each item in Objectmap
|
||||
*/
|
||||
forEach(functionArg:IObjectmapForEachFunction){
|
||||
forEach(functionArg: IObjectmapForEachFunction<T>) {
|
||||
return this.objectArray.forEach(functionArg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* wipe Objectmap
|
||||
*/
|
||||
wipe(){
|
||||
wipe() {
|
||||
this.objectArray = [];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user