now works with TypeScript Generic Types to track type usage of Objectmap
This commit is contained in:
@@ -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 = [];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user